2012-10-03 15 views
8

Ho il seguente helper date_select. Voglio aggiungere una classe ma non sta producendo l'HTML.Aggiunta di una classe CSS a date_select

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

Ho anche provato con un hash come alcune soluzioni suggeriscono ma ottengo un errore di sintassi:

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

Non sono sicuro io capisco quando e come formattarlo con un hash.

risposta

8

Questo dovrebbe funzionare:

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

Update: Per Rails 5

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

provare

clas all'interno html hash come :html=>{:class=>'input-mini'}

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

La risposta convalidato non ha funzionato per me, che cosa ha funzionato è stato:

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

Il che rende più senso secondo il docs:

date_select(object_name, method, options = {}, html_options = {}) 
0

Come si può vedere sul docs, il date_select aiutante vuole i parametri specifici:

date_select(object_name, method, options = {}, html_options = {}) 

Per me solo Non tiratevi aggiungere il meth od opzione e lasciare le opzioni di hash {} vuoto ha funzionato perfettamente:

datetime_select(:recipient, {}, {:class => 'custom-select'}) 

Oppure, se si desidera utilizzare con :birthday param si può semplicemente utilizzare:

datetime_select(:recipient, :birthday, {}, {:class => 'custom-select'}) 
Problemi correlati