Created
December 8, 2015 18:34
-
-
Save evanleck/46443f0e8dc9d629affb to your computer and use it in GitHub Desktop.
Simple Strong Parameters in Sinatra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
require 'sinatra/strong-params' | |
class ExampleApp < Sinatra::Base | |
configure do | |
register Sinatra::StrongParams | |
end | |
get '/', allows: [:search] do | |
# Only the 'search' parameter will make it to the execution scope. | |
end | |
post '/search', needs: [:search, :_csrf] do | |
# Will only ever return if both the 'search' and '_csrf' parameters are present. | |
# Otherwise, it will raise an instance of RequiredParamMissing | |
end | |
error RequiredParamMissing do | |
# Handle parameter failures here. | |
[400, "No dice"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment