Skip to content
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

Custom engine generator should create attributes whitelist now that rails requires you to do so #1578

Closed
murdoch opened this issue Apr 9, 2012 · 7 comments

Comments

@murdoch
Copy link

murdoch commented Apr 9, 2012

Rails 3.2.3 expects you to white-list your model's attributes before you can write to the db.

If you create a custom engine using rails g refinery:engine article attr1 attr2 attr3, then you will not be able save any records until you set attr_accessible in your model. Rails throws a mass-assignment error until you do. You will also need to include the refinery-generated position field in your whitelist.

@parndt
Copy link
Member

parndt commented Apr 9, 2012

hm this was done already https://github.com/resolve/refinerycms/blob/2-0-stable/core/lib/generators/refinery/engine/templates/app/models/refinery/namespace/singular_name.rb#L8

Can you try putting in your Gemfile:

gem 'refinerycms', :git => 'git://github.com/resolve/refinerycms.git', :branch => '2-0-stable'

bundle and generate the engine again.. does it still need attr_accessible?

@murdoch
Copy link
Author

murdoch commented Apr 9, 2012

It 'almost' fixes the problem. I ran the following code:

rails g refinery:engine facility name:string machine:integer city:string description:text tldr:text

And here is what refinery generated for me:

attr_accessible :name, :position
acts_as_indexed :fields => [:name, :city, :description, :tldr]

As you can see, attr_accessible is set, but only for the first attribute (and position), so I still get the mass assignment error.

@ugisozols
Copy link
Member

Imo user should take care of specifying which attributes he want's to allow to be mass-assigned. Refinery should not guess those attributes. For example what happens when I generate an engine with admin boolean attribute which I clearly don't want to be mass-assigned? I would have to go into model and delete it from attr_accessible ...

@parndt
Copy link
Member

parndt commented Apr 10, 2012

We should have best practice by default. Plus, this code's already in our codebase..

@ugisozols
Copy link
Member

@parndt what's best practice?

@parndt
Copy link
Member

parndt commented Apr 10, 2012

To make it work out of the box

@ugisozols
Copy link
Member

@parndt ^

parndt added a commit that referenced this issue Apr 23, 2012
Add all generated attributes to attr_accessible whitelist. #1578.
ugisozols added a commit that referenced this issue May 17, 2012
Conflicts:

	core/lib/generators/refinery/engine/templates/app/models/refinery/namespace/singular_name.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants