Skip to content

Instantly share code, notes, and snippets.

@alassek
Created March 16, 2011 19:58
Show Gist options
  • Select an option

  • Save alassek/873195 to your computer and use it in GitHub Desktop.

Select an option

Save alassek/873195 to your computer and use it in GitHub Desktop.
Get a flash message from a Rails Controller in a Sinatra action
def get_flash
signed_message = request.cookies['_project_name_session']
if signed_message.present?
secret = ProjectName::Application.config.secret_token
verifier = ActiveSupport::MessageVerifier.new(secret)
session = verifier.verify(signed_message)
@flash = session.delete('flash')
signed_message = verifier.generate(session)
response.set_cookie('_project_name_session', :value => signed_message, :path => '/')
end
end
@alassek

alassek commented May 12, 2011

Copy link
Copy Markdown
Author

Make sure you're setting the path in response#set_cookie or you will have a very strange session bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment