This repository was archived by the owner on Dec 12, 2021. It is now read-only.
Yet another strong params support#988
Open
bryanrite wants to merge 1 commit intoryanb:masterfrom
Open
Conversation
|
+1 @bryanrite this is a nice solution, thanks. |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Inspiration taken from #958, #911, and others.
This adds strong parameters support but with some smart defaults. Since strong_parameters really only affects cancan for
:createand:updateactions, we only apply params for those actions. Further more, by default, we try to run several methods in order:create_paramsorupdate_params(depending on the action you are requesting, allows you to override the following other methods if you have different params for creating and updating the resource)<model_name>_paramssuch as ability_params (the default rails 4 convention when naming your param method)resource_params(a generically named method... so you don't have to change the method name if you change your model name or cancan key)Further more, you can specify a custom method to run via the
param_methodoption:load_and_authorize_resource param_method: :my_sanitizerIt is also backwards compatible as if none of the methods are found it will carry on with the legacy way.
I've updated the readme and changelogs if we ever get a 1.6.11.