所以,当我这样做时:
<%= 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 & Carpenters</option>
<option value="136">Demolition</option>
<option value="137">Drywall</option>
<option value="139">Electricians</option>
<option value="141">Fences, Doors & Gates</option>
<option value="143">Flooring</option>
<option value="144">General Contractors</option>
<option value="145">Heating & 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 & Blinds</option>
<option value="14377">Architects</option>
<option value="14379">Alarms, Audio & 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 bootstrap模板,我希望生成的select尽可能看起来像这样:
<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 :(得分: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 gem来处理样式。
答案 1 :(得分: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"} %>