Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Form Label Helper

Form Label Helper

The usage is very simple from the simplest case to more complicated.

  • label_tag “First Name”, :for => “user_first_name”, :accesskey => “F”
  • label_for :user, :first_name
  • f.label :first_name

I have this helper default to my likings :D. For the exception of the label_tag in which you need to specify an accesskey option if you want it, for label_for and f.label the default is that the helpers figure out the first possible available letter to be used as access key. So in the previous case the output is:

<label accesskey="F" for="user_first_name">First Name</label>

label_for and f.label can take 2 extra parameters beside the usual suspects, :text (string) to be used instead of method.humanize and :skip_auto_accesskey (bool) if you don’t want to create the accesskey automagically.

Remember to put an entry in your stylesheet and you’re good to go. Ex: label kbd{text-decoration: underlined; font-family: inherit; font-size: inherit; font-style: inherit;}

When using f.label or label_for the label tag will get wrapped in a div.labelWithError in case an error exists on the object. The same way a f.input_field gets wrapped in a div.fieldWithError.

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly