helper colllection_select,参数个数错误(给定7,预期4..6)

时间:2016-05-13 07:00:54

标签: ruby-on-rails

在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' %> 

3 个答案:

答案 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: truevalidate :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--"  } %>