【发布时间】:2015-12-22 16:39:43
【问题描述】:
我想要一个选择标签来允许多项选择。我尝试了各种多种选择,但似乎都没有奏效。这是我现在拥有的(Ruby 2.x,Rails 4.x)
<div class="field">
<%= f.label :category %><br>
<%= f.select :category, options_for_select(@categories.sort),
:include_blank => true, :multiple => true %>
</div>
当我转到表单时,会列出项目,但我无法使用 Control 或 Shift 键选择多个项目。
我的搜索模型是
has_many :documents
def search_documents
documents = Document.all
documents = documents.where("document_title like ?", "%#{document_title}%") if document_title.present?
documents = documents.where("summary like ?", "%#{summary}%") if summary.present?
documents = documents.joins(:category).where("categories.name like ?", "%#{category}%") if category.present?
documents = documents.joins(:owner).where("owners.name like ?", "%#{owner}%") if owner.present?
documents = documents.where("doc_file_file_name like ?", "%#{file_name}%") if file_name.present?
return documents
end
如果我查看结果页面的源代码,则该倍数似乎不起作用
<div class="field">
<label for="search_category">Category</label><br>xxx
<select name="search[category]" id="search_category"><option value=""></option>
<option value="Apples">Apples</option>
<option value="Calendar">Calendar</option>
<option value="Cct Catalogs">Cct Catalogs</option>
<option value="Forms">Forms</option>
<option value="Sell Sheets">Sell Sheets</option></select>
</div>
我相信我在让搜索与多个项目一起工作时会遇到问题,但现在,我只是想解决下拉问题中的多选问题。
【问题讨论】:
标签: ruby-on-rails