Module: RailsConditionalParams::AliasPatch
- Defined in:
- lib/rails_conditional_params/alias_patch.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#permit_with_conditional_params(*filters) ⇒ Object
Adds support for conditional params:.
Class Method Details
.included(other) ⇒ Object
18 19 20 |
# File 'lib/rails_conditional_params/alias_patch.rb', line 18 def AliasPatch.included(other) other.alias_method_chain :permit, :conditional_params end |
Instance Method Details
#permit_with_conditional_params(*filters) ⇒ Object
Adds support for conditional params:
params.permit(yes: true, no: false)
# => { "yes" => "..." }
This is useful for parameters that should be permitted in some cases, but not others:
params.permit(:title, :body, published: admin?)
# Result only includes published if admin? is true.
13 14 15 16 |
# File 'lib/rails_conditional_params/alias_patch.rb', line 13 def permit_with_conditional_params(*filters) RailsConditionalParams.restructure_filters! filters permit_without_conditional_params(*filters) end |