I would like to mount a sinatra application in my rails app. But I would like this one to share the same layout.
The iframe could work but do you have any other idea ?
Thanks
I would like to mount a sinatra application in my rails app. But I would like this one to share the same layout.
The iframe could work but do you have any other idea ?
Thanks
to share the same layout, you can point sinatra to the folder where the layout is in your rails app: (taken from here: http://www.sinatrarb.com/configuration.html)
From your Rails app you can build a method which you can call from the action where the sinatra app should be included in the view. (given you want to use the index action for this)
see how rest-client works here: https://github.com/archiloque/rest-client and don't forget to include the gem in your rails app.
To use links in your sinatra app you should decide if sinatra should handle this (point to sinatra app (with port) or build links in your sinatra app which are handled by your rails app)
You basically need to do two things:
You need to tell the Rails router that a certain URL path is to be handled by another Rack app (in your case a Sinata app). This can be done by adding this to your routes.rb:
Having done that, you can create your app like so:
The second step now is to tell your Sinatra app to use the rails layout which by default lives in
app/views/layouts/application.html.erb
for Rails 3.1. by default, Sinatra uses./views/layout.ext
(withext
being the extension of your chosen template system). So you basically, have to tell Sinatra to./views
Both can be achieved by setting the following in your sinatra app:
I think that using the
append_view_path
in your rails application will work a little bit better. Just append the Sinatra views to your Rails app and it will look there after looking in app/views.The Crafting Rails Applications book by José Valim has a lot of documentation on that topic (rendering views from other sources), you may want to look at that.
Also, this Railscasts can help: http://railscasts.com/episodes/222-rack-in-rails-3