On Tue, Dec 16, 2008 at 10:17 PM, Tom Ha <[email protected]> wrote: > > Hi there, > > I have an instance of an object in my database and need to get out every > element of it, like this: > > Example: model = student > ======================== > > firstname = Fred > lastname = Williams > streetname = NULL > city = NULL > date of birth = 12.12.1934 > ... > (until there is no more column name left for this model) > > If it was an array, I'd use: .each { ... } > > How do I correctly/efficiently cycle through this one?
I don't know if its efficient, or right, but ActiveRecode::Base#attributes [1] seems to do the job If you already know the fields, you can also do something like that : [ :firstname, :lastname, ... ].each do |attr| val = model.send attr end Hope it will help [1] : http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002047 -- Gabriel Laskar <[email protected]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

