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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top