New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strong_params: Simpler modification of allowed params #3566
Conversation
I'm receiving syntax errors when trying to run the specs:
|
I'm running on Ruby 2.0.0 if that helps. |
With existing `ControllerHelpers::PermittedAttributes`, adding additional permitted attributes can only be done by overriding the method. To be done safely in extensions, this would rely on a lot of method aliasing. This introduces `Spree::PermittedAttributes`, which has as module attributes for the the accessible attributes on the spree models. This is easily modifiable by spree applications or extensions. Spree::PermittedAttributes.line_item_attributes << :my_custom_attribute `ControllerHelpers::StrongParameters` contains the same methods as before but mostly delegates to `Spree::PermittedAttributes`. The controller helpers also describe the allowed nested attributes. For more complex customization (ex. permissions depending on role), controllers can still override `permitted_attributes` with `SimpleDelegator` (or similar) or override `permitted_*_attributes` methods themselves to modify the attributes on a per request basis. Thanks to Hates, Radar, huoxito, and jstrong in #spree for quick discussion.
Ack! Sorry @JDutil, that was a fail commit. Pushed a typo-free one. |
Awesome, once this is in I can start updating a lot of extensions that used the older |
Knock yourself out @Hates :) |
Newbie question: Where is a line like |
Yea spree.rb should work fine. |
I think for development it might be better to add it in ApplicationController or some other file that gets reloaded with the app though. You might experience issues where rails would reload the app code and attributes would be missing on that class accessor |
Great point. I hate having to restart server for things. |
i am working on rails 4 but i am not able to save the value of customer_name in database. |
@rk-panchal first, there is a typo So you should do it like this:
|
thanks @Mafi88 |
With existing
ControllerHelpers::PermittedAttributes
, adding additional permitted attributes can only be done by overriding the method. To be done safely in extensions, this would rely on a lot of method aliasing.This introduces
Spree::PermittedAttributes
, which has as module attributes for the the accessible attributes on the spree models. This is easily modifiable by spree applications or extensions.ControllerHelpers::StrongParameters
contains the same methods as before but mostly delegates toSpree::PermittedAttributes
. The controller helpers also describe the allowed nested attributes.For more complex customization (ex. permissions depending on role), controllers can still override
permitted_attributes
withSimpleDelegator
(or similar) or overridepermitted_*_attributes
methods themselves to modify the attributes on a per request basis.Thanks to Hates, Radar, huoxito, and jstrong in #spree for quick discussion.