views:

26

answers:

1

is there a way to stop execution and return a different value in a before do block in sinatra ?

before do
   # code is here
   # I would like to 'return "Message"'
   # I would like "/home" to not get called.
end



// rest of the code

get '/home' do

end
+2  A: 

On http://www.sinatrarb.com/intro Filters section

Before filters are evaluated before each request within the context of the request and can modify the request and response. Instance variables set in filters are accessible by routes and templates:

  before do
    @note = 'Hi!'
    request.path_info = '/foo/bar/baz'
  end

  get '/foo/*' do
    @note #=> 'Hi!'
    params[:splat] #=> 'bar/baz'
  end
Shtirlic
does this mean if I reset request.path_info to a different value, the route will change ?
Prakash Raman