Am I correct in thinking that one cannot use attr_accessor in
ActiveRecord models?
I have success when using either cattr_accessor or mattr_accessor but
not the native Ruby method. Am I missing something here, or is this
how it really is?
I think I may be able to get to the point a bit better with 2 more
questions...
Am I correct in thinking that attr_accessor always returns or sets an
instance variable?
Another reason I'm confused, is that, when I set an attr_accessor :foo
in my model and then drop into script/console and call .methods on
that model instance, I never see "foo" or "foo=" in the methods list
when I run a search for them. Conversely when setting either
cattr_accessor :foo or mattr_accessor :foo shows the the two new
"foo" and "foo=" methods in the model's method list as expected.
Thats because mattr_accessor is at module level, cattr_accessor is at class level, and attr_accessor is at instance level. So you have to use class.instance_methods to find your method – like this: