2012-10-03 26 views
8

Mam następujący pomocnika date_select. Chcę dodać klasę, ale nie produkuje ona kodu HTML.Dodawanie klasy CSS do date_select

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

Ja również próbowałem go z mieszania jak sugerują niektóre rozwiązania, ale pojawia się błąd składni:

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

Nie jestem pewien czy naprawdę zrozumieć, kiedy i jak sformatować go z hash.

Odpowiedz

8

To powinno działać:

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

Update: dla szyn 5

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

spróbować

clas wewnątrz html hash jak :html=>{:class=>'input-mini'}

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

Potwierdzone odpowiedź nie działa dla mnie, co zadziałało było:

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

co sprawia, że ​​więcej sensu według docs:

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

Jak widzimy na docs The date_select pomocnika chcą specyficzne parametry:

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

Dla mnie po prostu nie dodawaj do met od opcja i opuścić opcje mieszania {} pusty pracował idealnie:

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

Lub jeśli chcesz korzystać z :birthday param można po prostu użyć:

datetime_select(:recipient, :birthday, {}, {:class => 'custom-select'}) 
Powiązane problemy