Rails 2.1 Label

A label method is introduced in Rails 2.1.

The following code:

[sourcecode language="html"]

< % form_for (@post) do |f| %>

< %= f.label :title %>

#Code truncated for clarity
< % end %>

[/sourcecode]

Would generate the following HTML:

[sourcecode language="html"]

[/sourcecode]

If your label contains a css class and if you need another name other than the default column name for your label, just do as following:

[sourcecode language="ruby"]
< %= f.label :title, "Please key in a title", :class => “form_label” %>
[/sourcecode]

The code above will generate the following:
[sourcecode language="html"]

[/sourcecode]

Tags:

No comments yet.

Leave a Reply