Sinatra is a web application framework for rapidly building applications in Ruby. Sinatra is a domain specific language or DSL which means it is designed from the ground up to build applications with minimal efforts. It is written in Ruby.
Sinatra framework interview questions
- 1) What is Sinatra?
- 2) How to use sessions in Sinatra?
- 3) How do you flash a session message in Sinatra ?
- 4) How do I get the “route” for the current page?
Download Sinatra framework interview questions PDF
Below are the list of Best Sinatra framework interview questions and Answers
Sinatra is web application framework for rapidly building applications in Ruby.Sinatra is a domain specific language or DSL which means it is designed from the ground up to build applications with minimal efforts.It is written in Ruby and an alternative to Ruby web application frameworks such as Ruby on Rails, Merb, Nitro, and Camping.
By default, Sessions are disabled in Sinatra.You need to enable them and then use the session hash from routes and views. Below code shows how to enable, set or get a session in Sinatra.
//Enabling Session enable :sessions get '/foo' do // setting session value session[:message] = 'Hello World!' redirect to('/bar') end get '/bar' do // getting session value session[:message] # => 'Hello World!' end
Rack:: Flash is used to flash a message in Sinatra.
Example Usage :
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
The request object probably has what you’re looking for:
get '/hello-world' do request.path_info # => '/hello-world' request.fullpath # => '/hello-world?foo=bar' request.url # => 'http://example.com/hello-world?foo=bar' end
Also Read Related Sinatra framework interview questions
|Ruby on Rails Interview Questions|
Subscribe Our NewsLetter
Never Miss an Articles from us.
- Common Interview Questions
- Python Flask Interview Questions
- NoSQL interview questions
- JQuery Interview Questions
- C programming interview questions
- AngularJS Interview Questions
- Node JS Interview Questions with Express
- Core Java interview questions
- HTML Interview Questions
- Laravel interview questions
- Wordpress Interview Questions
- PHP Interview Questions