Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Before-filter for all POST requests in Sinatra?

Is there a way to create a "before" filter to capture and pre-process all POST requests in Sinatra?

like image 530
Arman H Avatar asked Mar 27 '13 22:03

Arman H


1 Answers

One way of doing this would be to create a custom condition to use in the filter:

set(:method) do |method|
  method = method.to_s.upcase
  condition { request.request_method == method }
end

before :method => :post do
  puts "pre-process POST"
end 
like image 168
matt Avatar answered Oct 19 '22 02:10

matt