FormBuilder-friendly labels?

I’m trying to find a good way to emit tags inside a form_for()
block, without needing to repeat the name of the instance variable
constantly. Is there a better way to do this than the snippet below,
or do I need to do a little extension to the FormBuilder itself?

<% form_for :long_example_name, @long_example_name,
:url => { :action => :new } do |f| %>
<%= label_tag “long_example_name[some_attribute]”, “Some Attribute:”
<%= f.text_field :some_attribute %>

<%= label_tag "long_example_name[some_other_attribute]", "Some

Other Attribute:" %>
<%= f.text_field :some_other_attribute %>

<%= label_tag "long_example_name[yet_another_attribute]", "Yet

Another Attribute:" %>
<%= f.text_field :yet_another_attribute %>
<% end -%>

I’d like to avoid repeating the “long_example_name” inside the
builder, because it wears my fingers out, and makes it harder to
refactor later.
Sadly, you can’t just say:
f.label_tag :some_other_attribute, "Some Other Attribute: "

Any ideas?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs