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
Instance variables set in before filters and routes are accessible by after filters:
after do puts response.status endNote: Unless you use the
body
method rather than just returning a
String from the routes, the body will not yet be available in the
after filter, since it is generated later on.
before '/protected/*' do authenticate! end after '/create/:slug' do |slug| session[:last_slug] = slug end
before :agent => /Songbird/ do # ... end after '/blog/*', :host_name => 'example.com' do # ... end