Skip to content

Rails 2.1 Label

June 14, 2008
tags:

A label method is introduced in Rails 2.1.

The following code:


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

    <%= f.label :title %>

#Code truncated for clarity
<% end %>

Would generate the following HTML:

<label for="post_title">Title</label>

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:

<%= f.label :title, "Please key in a title", :class => "form_label" %>

The code above will generate the following:

<label for="post_title" class="form_label">Please key in a title</label>
Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: