Rails - How to declare attr_accessible for multiple roles without duplication

Viewed 3564

Is there a way to declare attr_accessible for multiple roles without a ton of duplication?

If I have several user roles, and each role is allowed to edit a different subset of attributes, here's what my attr_accessible declaration looks like:

attr_accessible :first_name, :last_name, :active, :as => :admin
attr_accessible :first_name, :last_name, :as => :manager
attr_accessible :first_name, :last_name, :as => :guest

I'd like to either

  • A) define an array of accessible attributes that can be shared among different roles or
  • B) define an array of roles than can access the same attributes

Is this possible?

3 Answers
Related