Skip to content

Instantly share code, notes, and snippets.

@evanleck
Created December 8, 2015 18:39
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/1a09456364e205d12038 to your computer and use it in GitHub Desktop.
Save evanleck/1a09456364e205d12038 to your computer and use it in GitHub Desktop.
Simple Strong Parameters in Sinatra
#
# A way to whitelist parameters.
#
# get '/', allows: [:id, :action] do
# erb :index
# end
#
# Modifies the parameters available in the request scope.
# Stashes unmodified params in @_params
#
app.set(:allows) do |*passable|
condition do
unless @params.empty?
@_params = @_params || @params # for safety
globals = settings.globally_allowed_parameters
passable = (globals | passable).map(&:to_sym) # make sure it's a symbol
# trim the params down
@params = @params.select do |param, _value|
passable.include?(param.to_sym)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment