0

I almost always use attr_accessible in my Rails models.

Is there a generator flag or other terminal command to haveattr_accessible and the model fields automatically inserted into the model file when I run a relevant generator?

Clay
  • 2,949
  • 3
  • 38
  • 54

2 Answers2

1

Not sure about that. But you can annotate your models using this gem.

It will add schema info in the model files as comments at the top of the file. Maybe that could help you in some way to create attr_accessible fields.

Phyo Wai Win
  • 1,160
  • 6
  • 14
0

Rails airs on the opinion that all the fields are accessible (outside of ID) unless you don't want them to be.

You could write your own generators to override the default ones if it's a major pain point. One thing I suggest is, that if your attr_accessible is a lot of work for you to do for each model, would using attr_protected be better suited for your tasks?

MunkiPhD
  • 3,636
  • 1
  • 29
  • 51
  • I don't usually want them all to be. My major issue is just a workflow one -- I forget to do it or I'm just plain forgetful and then I have to bounce between the schema file and the model file to remember. – Clay Feb 13 '12 at 18:44
  • Then yeah, the Annotate gem is golden. – MunkiPhD Feb 13 '12 at 21:02