your_model.instance_variables.each do |i| if your_model.instance_variable_get(i).instance_of?(Array) then #your code to do anything with your_model.instance_variable_get(i) what is a value end end
If you have an active record model, you can do:
@account = Account.first Account.column_names.each do |i| @account.instance_eval(i) # row returns @account.name for example inside the loop, next @account.address and so on end
That's all!
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete