Search code examples
ruby-on-railsrubyarraysmetaprogramminghstore

How to collect all atrributes of Model including these from Hstore?


Right now to collect all attributes names I have to:

@attr_names = (User.attribute_names + User.accessible_attributes.to_a - ["", "data"]).uniq

Is there a better way to do that?


Solution

  • A slight improvement (assuming User.attribute_names and User.accessible_attributes.to_a do not each involve a duplicate):

    @attr_names = (User.attribute_names | User.accessible_attributes.to_a) - ["", "data"]