How to custamize DATE field in Rails 3

Hi friends,

When we use “date” field in rails (i.e) Date of birth, it usually shows 11 years. (i.e) The current year + previous 5 years + next 5 years.

But if we need a list of particular years like 1970 to 1980, we can do that by specifying, the “:start_year” and “:end_year“, in the “date” field. 🙂

The Embedded Ruby (i.e “erb”) syntaxes are :start_year => 1975, :end_year => 1990


In /app/view/user/_from.html.erb we simply specify the above syntax, we can do that.

<strong><span style="color: #ff6600;"> <span style="color: #ff6600;"><%= f.label :dob %></span><br /></span></strong>
<span style="color: #ff6600;"> <%= f.date_select :dob  %></span>
<span style="color: #ff6600;"> </div></span>


<span style="color: #ff6600;"> <%= f.date_select :dob ,
 <span style="color: #ff6600;">:start_year => 1980,     :end_year => 1995 %></span></span>
<span style="color: #ff6600;"> </div></span>


This slideshow requires JavaScript.

That’ s all Simple but power full 🙂 😛


Leave a Reply

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

You are commenting using your 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