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
before do
halt 401, {'Content-Type' => 'text/plain'}, 'Message!'
end
You can specify only status if you want, here's example with status, headers and body
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With