views:

121

answers:

1

In the User model I have two accepts_nested_attributes_for: :details (which is has_one association) and :membership_orders (has_many).

For :details I have:

attr_accessible :details_attributes

But for the membership_orders I can't have so simple accessor, because I want to protect it from the normal user, but make it accessible for the admin.

It's possible to do with attribute-permissions plugin (github.com/Fingertips/attribute-permissions/tree/master), but I think it's not the finest solution.

Can you tell me how I can add special expression for the attr_accessible, or maybe filter out those attributes using before_validation (or what-else).

You can read about this problem by this link: blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/

Thanks.

A: 

You could certainly filter them out before validation. Another option is to switch to attr_protected and specify the fields you want protected instead of the ones you want open. That could be a simple switch or a more involved one, depending on the size of your models.

Robert Rouse
Dmitry Polushkin