I am using a hash to fill out some forms. One of them is the user information. I am using this Hash successfully in the user registration form. The idea was to use the same Hash to fill out the edit form, as follows:
<% NEW_USER_HASH.each do |column_name,field_info| %>
<div class="field">
<% if field_info["type"] != "hidden_field" %>
<%= f.label field_info["label"] %>
<% end %>
<%= f.send(field_info["type"].to_sym, column_name , :value => @user.column_name) %>
</div>
<% end %>
But I am getting the following error message:
undefined method `column_name'
I tried the following variations with the same results:
:value => @user.column_name.to_s
:value => @user.column_name.to_sym
Any ideas?
ANSWER:
column_name is not an @user method, so the answer is to use the send method, with the variable column_name as a parameter.
So, replace:
:value => @user.column_name
With
:value => @user.send(column_name)
I think the culprit is
@user.column_name. One way is to use eval(“@user.” + column_name). Better way is what I have shown below.Try this:
Let me know if this works.
Good luck!