Created
June 5, 2013 22:56
-
-
Save hrdwdmrbl/5717968 to your computer and use it in GitHub Desktop.
Strong Parameters -- HowTo Custom PERMITTED_SCALAR_TYPES
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.