I’m adding “:foo” attribute to my user model as:
attr_accessor :foo
attr_accessible :foo
But when I set this attribute from a session controller or any other controller as:
User.foo = "my attributre"
and I get this attribute as:
User.foo
so these are not recognize and gives me an error, which is:
undefined method `foo=' for #<Class:0xb75366fc>
So please help here. I AM USING RAILS 2.3.5
attr_accessordoes not create a class method, it creates instance methods. So given your code, it should work to use:Edit:
However, if you do want to create custom methods, then you could do something like this:
And then you call it from your Controller: