Give access to GET/POST params in filters
This commit is contained in:
parent
c9ca8a74f6
commit
8dbd919f45
|
@ -329,6 +329,8 @@ module Sinatra
|
|||
|
||||
private
|
||||
def dispatch!
|
||||
@params = original_params = nested_params(@request.params)
|
||||
|
||||
self.class.filters.each do |block|
|
||||
res = catch(:halt) { instance_eval(&block) ; :continue }
|
||||
return unless res == :continue
|
||||
|
@ -336,7 +338,6 @@ module Sinatra
|
|||
|
||||
if routes = self.class.routes[@request.request_method]
|
||||
path = @request.path_info
|
||||
original_params = nested_params(@request.params)
|
||||
|
||||
routes.each do |pattern, keys, conditions, method_name|
|
||||
if match = pattern.match(path)
|
||||
|
|
|
@ -72,4 +72,15 @@ describe "Filters" do
|
|||
assert ok?
|
||||
assert_equal 'cool', body
|
||||
end
|
||||
|
||||
it "gives you access to params" do
|
||||
mock_app {
|
||||
before { @foo = params['foo'] }
|
||||
get('/foo') { @foo }
|
||||
}
|
||||
|
||||
get '/foo?foo=cool'
|
||||
assert ok?
|
||||
assert_equal 'cool', body
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue