8
votes

I have dynamic form which has a set of values. I created a partial which contains text fields which I display. Next to each of them I would like to display a label containing the title of the text. For instance First Name, and Last Name would not be known previously. How do I go about doing that? It seems that I cannot access the attributes directly. But when I use the label field, the variable name in the label is displayed not the actual value.

3
Could you try to explain what you want to accomplish better? Maybe give an example? I have tried to understand in order to help you but I can't understand what you need. - Petros
I have an object which has a one-to-many relation with a set of Dynamic Fields {Name,Value}. When a user is updating the dynamic fields I want to display the name of the fields as the actual label instead of the hardcoded label. Or a predetermined String value. The dynamic form is inside a partial and all data. Snippets: _form.erb <% f.fields_for :entity_values do |builder| %> <%= render "entity_value_fields", :f => builder%> <% end % _entity_value_fields.erb <%= f.label :name %> {label needs to be the dynamic name of that value} <%= f.text_field :value %> ... - sebajb

3 Answers

6
votes

Well! This was a reflection of how new I am to rails. You can do this by using f.object.{attr_name} and that worked.

5
votes

f.object.{attr_name} didn't work for me, but f.object[:attr_name] did.

2
votes

What about:

f.object.send(attr_name)

That would be the Rubyish way.