Skip to content
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
bryanrite:yet_another_strong_params_support
Open

Yet another strong params support#988
bryanrite wants to merge 1 commit intoryanb:masterfrom
bryanrite:yet_another_strong_params_support

Conversation

@bryanrite
Copy link
Copy Markdown

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 :create and :update actions, we only apply params for those actions. Further more, by default, we try to run several methods in order:

  • create_params or update_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>_params such 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_method option:

load_and_authorize_resource param_method: :my_sanitizer

It 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.

@james2m
Copy link
Copy Markdown

james2m commented Jan 31, 2014

+1 @bryanrite this is a nice solution, thanks.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants