Looping over attributes of object of a Non-Active-Record-Model
ruby, ruby-on-rails, ruby-on-rails-3
Solution
This is the best way I found
item=self.instance_values.symbolize_keys
item.each do |k,v|
...
..
end
There is a code to show it's usage here (look at the update in the question itself) - Grouping via an element in hash
Problem
The simple way to loop over all attributes of an object when using Active Record is ``` order_item_object.attributes.each do |key,value| .... end ``` But this doesn't work, when we are not using Active Record. How can I iterate over all the attributes of an object then? For eg -: I have a model in Rails which does not use active record. The object from model order_item can be used in the controller like order_item_object.product_id, order_item_object.quantity, order_item_object.quoted_price. But when I try to `order_item_object.attributes.each do |k,v|` ...., I get `undefined method "attributes" for #<Order:0x00000005aa81b0>` How should I go about this?