Tag Archives: Ruby

A Sinatra before only filter

In a Sinatra application you can use the ‘before’ filter to run something before every each event.

before do
puts “I will run all the time…”
end

Here’s a module that will allow you to run code only before certain routes:

module Sinatra

module BeforeOnlyFilter
def before_only(routes, &block)
before [...]