Module: Sinatra::RequiredParams
- Defined in:
- lib/sinatra/required_params.rb
Overview
Sinatra::RequiredParams
Ensure required query parameters
Usage
Set required query parameter keys in the argument. It’ll halt with 400 if required keys don’t exist.
get '/simple_keys' do
required_params :p1, :p2
end
Complicated pattern is also fine.
get '/complicated_keys' do
required_params :p1, :p2 => [:p3, :p4]
end
Classic Application
In a classic application simply require the helpers, and start using them:
require "sinatra"
require "sinatra/required_params"
# The rest of your classic application code goes here...
Modular Application
In a modular application you need to require the helpers, and then tell the application to use them:
require "sinatra/base"
require "sinatra/required_params"
class MyApp < Sinatra::Base
helpers Sinatra::RequiredParams
# The rest of your modular application code goes here...
end
Instance Method Summary collapse
Instance Method Details
#required_params(*keys) ⇒ Object
49 50 51 |
# File 'lib/sinatra/required_params.rb', line 49 def required_params(*keys) _required_params(params, *keys) end |