Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a CSS class to date_select

I have the following date_select helper. I want to add a class but it's not producing the HTML.

<%= date_select :recipient, :birthday, :order => [:day, :month, :year], :start_year => 1920, :end_year => 2013, :class => "input-mini" %>

I've also tried it with a hash as some solutions suggest but I get a syntax error:

<%= date_select :recipient, :birthday, :order => [:day, :month, :year], :start_year => 1920, :end_year => 2013, {:class => "input-mini"} %>

Not sure I really understand when and how to format it with a hash.

like image 919
Matt Wheeler Avatar asked Oct 03 '12 18:10

Matt Wheeler


2 Answers

The validated answer did not work for me, what worked was:

<%= date_select
    :recipient,
    :birthday,
    {:order => [:day, :month, :year], :start_year => 1920, :end_year => 2013},
    {:class => "input-mini"}
%>

Which makes more sense according to the docs:

date_select(object_name, method, options = {}, html_options = {})
like image 78
standup75 Avatar answered Nov 02 '22 22:11

standup75


This should work:

<%= date_select :recipient, :birthday, 
:order => [:day, :month, :year], 
:start_year => 1920, 
:end_year => 2013, 
:html=>{:class => "input-mini"} 
%>

Update: For Rails 5

<%= date_select :recipient, :birthday, 
               {
                :order => [:day, :month, :year], 
                :start_year => 1920, 
                :end_year => 2013
               }, 
               {:class => "input-mini"}  %>
like image 22
Mario Avatar answered Nov 02 '22 21:11

Mario