Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spree 2.1 strong parameters

Is there a easy way to add a new permitted parameter to controllers in Spree without altering the defaults ?

I'm trying to change the orders_params method in OrdersController.

like image 466
Cassio Cabral Avatar asked Jan 23 '14 21:01

Cassio Cabral


2 Answers

You don't need to override anything, you have to do this in your spree initializer

To add a strong param to products controller...

Spree::PermittedAttributes.product_attributes << :new_attribute

and so on..

check this file: https://github.com/spree/spree/blob/master/core/lib/spree/permitted_attributes.rb?source=c

or this blog post: http://blog.crowdint.com/2014/06/24/how-to-add-custom-attributes-in-spree.html

like image 200
Steven Barragán Avatar answered Oct 17 '22 17:10

Steven Barragán


You'll probably want to override this function:

https://github.com/spree/spree/blob/v2.1.4/core/lib/spree/core/controller_helpers/strong_parameters.rb#L28-L32

to include the parameters you want. The Spree Logic Customization Guide should give you instructions on how to override that method in that class easily.

like image 40
gmacdougall Avatar answered Oct 17 '22 18:10

gmacdougall