Iterating over an ActiveRecord object's properties

ruby-on-rails

Solution

Have you tried `object.attributes`? This will give you a hash of all the attributes on the object mapping the attribute name to the attribute value.

Problem

I'm trying to iterate over the properties of an ActiveRecord object. I've been searching online but I keep coming up blank. I thought I was getting warm with object.to_enum, but despite the fact that this returns an Enumerator object, I still get the error saying that 'each' is undefined for my object. Calling object.methods gives me a bunch of inherited stuff I don't want. Calling object.instance_variables doesn't give me anything close to what I seek. I'm guessing this isn't hard, but I just haven't figured it out yet :) Can anyone help? Thanks!

Original source