I need to access attribute names of a model but it is not showing all of them.
I have User model and I added a attr_accessor :color in it (since I don’t want to store this on my database as column).
But if I try to access attribute names using User.first.attribute_names it is showing only database columns,it is not showing ‘color’ attribute,so how do I access all the attributes ?is there any methods which list attr_accessor as attributes ?
First of all if you don’t know difference b/w attr_acessabe and attr_accessor look at
How to iterate ActiveRecord Attributes, including attr_accessor methods
you can add attr_accessor if you don’t an attribute to save in database then add that att_accessor to attr_accessable 🙂
now