New label helper

Bump: http://dev.rubyonrails.org/ticket/7139

Thoughts? (Not for 1.2, but in general)

//jarkko

I thought rails needed a label helper at first, but then I decided that form builders fill the gap just fine as well as allowing more flexibility and control.

I have my own form builder for example that automatically associates labels with my controls without me needing to specify them in my view, so this also cuts down on the code I need to write in my view.

I figure not having a label helper in rails forces people to do things like use a form builder, which I think is the better approach. It's sorta like how using form_tag in rails 1.2 can only be closed by using the '</form>' html tag. It makes people think it doesn't feel right, which is why you use should use form_for instead.

I personally say no to a label_helper in rails. :slight_smile:

Andrew,

label_for is not meant to compete with custom form builders, it's meant to complement them and be a building block for them and at the same time be really useful for cases where you don't want to use a full-blown builder. I would say anything that fosters the use of label tags in Rails apps (*cough*, Basecamp login, *cough*) is worthwhile.

//jarkko

I agree - anything to encourage label's is great. Most browsers shift focus to the "for" attribute on click. But even without that, a label tag is semantically correct in describing a form element.

I submitted my first patch that add labels for the generated scaffold source for resources: http://dev.rubyonrails.org/ticket/7091

Great! And if these both patches were accepted, the code in your patch would be even leaner:

<label for="<%= singular_name %>_<%= attribute.name %>"><%= attribute.column.human_name %></label><br />

=>

<%= f.label_for(attribute.name, attribute.column.human_name) %><br />

//jarkko