I have a project that uses Sinatra for static pages and Rails for the application.
I allow the request to hit one or the other by doing this in config.ru:
run Rack::Cascade.new([
EightyEightTactical::Root,
EightyEightTactical::Application
])
Where EightyEightTactical::Root is a subclass of Sinatra::Base and EightyEightTactical::Application is a subclass of Rails::Application.
I’m in a tricky situation where I need to set a flash message in a Rails controller and display it in a Sinatra layout.
I notice that Rails uses ActionDispatch::Flash in middleware, but I can’t seem to figure out how to access the flash messages outside of a Rails app. Am I mistaken, or can this be done?
Assuming you are using a Cookie session store, you can do the following:
1) Access the session cookie with the name specified in
config/initializers/session_store.rb.2) Decrypt the session cookie to get the session hash
3) Access the key called
flashwhich contains a hash.4) Iterate and display the flash message.
You should look at ActionController::Session::CookieStore class for more details.