Run Sinatra along with Rails

Sinatra is much better than rails for writing API codes and small functionalities, We can run sinatra app inside rails application.

Write your sinatra codes inside library folder of rails application, you can call rails application database tables from sinatra app also.

Then on your rails app config.ru

# This file is used by Rack-based servers to start the application.

require ::File.expand_path(‘../config/environment’, __FILE__)

require_relative ‘lib/api’

map ‘/api’ do
run API::SinatraApp.new
end

map ‘/’ do
run Rails.application
end

Put this code, so normal request goes to rails controller and  request url with /api goes to sinatra app. This way we can use both rails app and sinatra app together.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s