How do you output all attributes including attr_accessor attributes?
-
06-06-2021 - |
Domanda
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?
Soluzione
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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow