Question

Let's say I have a user class with columns name and email:

Class User < ActiveRecord::Base
  attr_accessor :gender
end

user = User.new(:gender => 'male', :name => 'joe', :email => 'user@example.com')

If I want the attributes I usually can do user.attributes, or user.inspect, or user.to_yaml. However this does not output the gender. Is there a way I can easily output everything?

Was it helpful?

Solution

I don't believe it what you're trying to do is easily possible to do.

See this question:

How to iterate ActiveRecord Attributes, including attr_accessor methods

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top