Return another value from pre before in sinatra block

Is there a way to stop execution and return a different value in the pre before in sinatra block?

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 
+4
source share
2 answers
 before do halt 401, {'Content-Type' => 'text/plain'}, 'Message!' end 

You can specify only the status, if you want, here is an example with the status, headers and body

+8
source

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

Before filters are evaluated before each request in the context of the request and can change 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 
+2
source

All Articles