2013-07-23 87 views
0

所以,當我做:自定義多種選擇輸入

<%= f.input :categories, :required => false, :as => :select, :input_html => {:size => 29, :multiple => true}, :collection => CategoriesList.all %> 

我目前有:

<div class="control-group"> 
    <div class="select input optional" id="filters_categories_input"> 
    <input name="filters[categories][]" type="hidden" value=""> 
    <label class=" control-label" for="filters_categories">Categories</label> 
    <input name="filters[categories][]" type="hidden" value=""> 
    <select id="filters_categories" multiple="multiple" name="filters[categories][]" size="29"><option value="133">Bathroom Remodeling</option> 
     <option value="134">Cabinets &amp; Carpenters</option> 
     <option value="136">Demolition</option> 
     <option value="137">Drywall</option> 
     <option value="139">Electricians</option> 
     <option value="141">Fences, Doors &amp; Gates</option> 
     <option value="143">Flooring</option> 
     <option value="144">General Contractors</option> 
     <option value="145">Heating &amp; Air Conditioning</option> 
     <option value="146">Kitchen Remodeling</option> 
     <option value="147">Landscaping</option> 
     <option value="149">Painters</option> 
     <option value="150">Plumbers</option> 
     <option value="151">Roofing</option> 
     <option value="152">Swimming Pools</option> 
     <option value="154">Windows &amp; Blinds</option> 
     <option value="14377">Architects</option> 
     <option value="14379">Alarms, Audio &amp; Video</option> 
     <option value="14381">Interior Designers</option> 
     <option value="14382">Pool Services</option> 
     <option value="36608">Cleaning Services</option> 
     <option value="37012">Commercial Contractors</option> 
     <option value="37013">Custom Home Builders</option> 
     <option value="37014">Handymen</option> 
     <option value="37045">Locksmiths</option> 
     <option value="37074">Home Inspectors</option> 
     <option value="37080">Hauling Services</option> 
     <option value="37086">Telecommunications</option> 
     <option value="40301">Concrete</option> 
     <option value="55555">Remodeling</option></select> 
</div> 
</div> 

但我必須整合Twitter的引導模板,我想產生看選擇儘可能像這樣:

<div class="control-group"> 
<label class="control-label">Multiple Select input</label> 
<div class="controls">         <select multiple>         <option>First option</option>          <option selected>Second option</option>        <option>Third option</option> 
<option>Fourth option</option> 
<option>Fifth option</option> 
<option>Sixth option</option> 
<option>Seventh option</option> 
<option>Eighth option</option> 
</select> 
</div> 
</div> 

但我不知道該怎麼做。

回答

0

選項1)
首先,你f.input分成f.label和f.select, 這樣它看起來像:

<%=f.label "Multiple Select Input"%> 
<%= f.select :categories, CategoriesList.all.collect {|x| [x.category, x.id]}, {}, :multiple => true %> 

隨後用所需的div包裹它:

<div class="control-group"> 
<%=f.label "Multiple Select Input", :class => "control-label"%> 
    <%= f.select :categories, CategoriesList.all.collect {|x| [x.category, x.id]}, {}, :multiple => true, :class => "controls" %> 
</div> 

選項2)
使用twitter-bootstrap-rails GE這將會照顧造型。

0

f.select不接受超過四個參數。所以聲明

<%= f.select :categories, CategoriesList.all.collect {|x| [x.category, x.id]}, {},:multiple => true, :class => "controls" %> 

會拋出錯誤。相反,你可以做類似如下:

<%= f.select :categories, CategoriesList.all.collect {|x| [x.category, x.id]}, {},{:multiple => true, :class => "controls"} %>