Skip to content

Instantly share code, notes, and snippets.

@evanleck
Created December 8, 2015 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanleck/46443f0e8dc9d629affb to your computer and use it in GitHub Desktop.
Save evanleck/46443f0e8dc9d629affb to your computer and use it in GitHub Desktop.
Simple Strong Parameters in Sinatra
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