在collection_select中,我需要传递以下参数。总计7,但方法接受最多6,我怎么加入?
<%= f.collection_select :skill_list, Project.tag_counts_on(:skills).order(:name), :id, :name, {}, {multiple: true}, validate: true, class: 'form-control' %>
答案 0 :(得分:1)
尝试使用此语法
//set cookie
function setCookie(cname,cvalue,exdays) {
var url = window.location.pathname;
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
if(url.indexOf('wholesale') > -1) {
document.cookie = cname+"="+cvalue+"; "+expires+";path=/wholesale";
} else {
document.cookie = cname+"="+cvalue+"; "+expires;
}
}
答案 1 :(得分:0)
错误的参数数量(给定7,预期4..6)
问题是你将参数传递给collection_select
是错误的。
collection_select(对象,方法,集合,value_method, text_method,options = {},html_options = {}
multiple: true
和validate :true
应取代options = {}
而class: 'form-control'
应该进入html_options = {}
。以下应该有效
<%= f.collection_select :skill_list, Project.tag_counts_on(:skills).order(:name), :id, :name, {multiple: true, validate: true}, class: 'form-control' %>
答案 2 :(得分:0)
您可以使用以下代码段用集合填充select
标签
<%= form.select :project, options_from_collection_for_select(Project.all, "id", "title"),{class: "project_title", include_blank: "--Please Select--" } %>