Forum: Ruby on Rails FormBuilder-friendly labels?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Wilson B. (Guest)
on 2006-04-06 23:25
(Received via mailing list)
I'm trying to find a good way to emit <label> 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 topic is locked and can not be replied to.