How do you flash a session message in Sinatra ?

devquora
devquora

Posted On: Feb 22, 2018

 

Rack:: Flash is used to flash a message in Sinatra.
Example Usage :
require 'sinatra/base'
require 'rack-flash'

class MyApp < Sinatra::Base enable :sessions use Rack::Flash post '/set-flash' do # Set a flash entry flash[: notice] = "Thanks for signing up!" # Get a flash entry flash[:notice] # => "Thanks for signing up!"
    
    # Set a flash entry for only the current request
    flash.now[: notice] = "Thanks for signing up!"
  end
end

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Sinatra Framework Interview Questions

    What is Sinatra?

    Sinatra is web application framework for rapidly building applications in Ruby.Sinatra is a domain specific language or..

    Sinatra Framework Interview Questions

    How to use sessions in Sinatra?

    By default, Sessions are disabled in Sinatra.You need to enable them and then use the session hash from routes and view..

    Sinatra Framework Interview Questions

    How do I get the “route” for the current page?

    The request object probably has what you’re looking for:get '/hello-world' do request.path_info # =&gt; '/hello-w..