Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hrdwdmrbl/5717968 to your computer and use it in GitHub Desktop.
Save hrdwdmrbl/5717968 to your computer and use it in GitHub Desktop.
Strong Parameters -- HowTo Custom PERMITTED_SCALAR_TYPES
# config/initializers/strong_paramters_permitted_scaler_values.rb
ActionController::Parameters.send :define_method, :permitted_scalar? do |value|
[String,
Symbol,
NilClass,
Numeric,
TrueClass,
FalseClass,
Date,
Time,
# DateTimes are Dates, we document the type but avoid the redundant check.
StringIO,
IO,
ActionDispatch::Http::UploadedFile,
Rack::Test::UploadedFile,
MyClass # Throw anything you want in this array to whitelist it.
].any? {|type| value.is_a?(type)}
end
@hrdwdmrbl
Copy link
Author

What I'm doing is redefining the method here https://github.com/rails/strong_parameters/blob/master/lib/action_controller/parameters.rb#L149 to be something I want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment