views:

14

answers:

1

I've got a class structure similar to this for a family of classes using STI

class Root < ActiveRecord::Base
   attr_accessible :root_prop
end

class Child < Root
  attr_accessible :child_prop
end

class Grandchild < Child
  attr_accessible :gc_prop
end

All my properties were working fine until I added the attr_accesible markers, so I know it is related to that. Now it appears that the properties giving accessible status on the base classes are not getting set. Does attr_accessible need to be set completely for each class, or do I need to look somewhere else for the reason for the values not getting set?

A: 

The comment here is the answer. The attr_accessible method does work for derived classes. However, when dealing with associations, the accessible attribute requires the _id suffix

class Grandchild < Child
  attr_accessible :associated_class_id
  belongs_to :associated_class
end

Is the correct way to mark an association with the attr_accessible method. This detail was missing from the original question.

Steve Mitcham