Sinatra Basics : Sinatra Filters
To learn how to use before and after filters in Sinatra.
require 'sinatra' before do puts "Before called" end get '/' do 'hello' end
bundle exec shotgun filter.rb
Browser output: hi
Server log output : Before called
Add after filter:
after do puts 'after called' end
so the file now looks like this:
require 'sinatra' before do puts "Before called" end after do puts 'after called' end get '/' do 'hello' end
Reload the browser.
is seen in the server log.
In this article, you learned how to use before and after filter in a Sinatra application.
Ace the Technical Interview
- Easily find the gaps in your knowledge
- Get customized lessons based on where you are
- Take consistent action everyday
- Builtin accountability to keep you on track
- You will solve bigger problems over time
- Get the job of your dreams
Take the 30 Day Coding Skills Challenge
Gain confidence to attend the interview