Ruby on rails RubyonRails集合选择

Ruby on rails RubyonRails集合选择,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,嗨,我一直在关注这个文档 还是没能在我的应用程序上运行 我不断地收到 参数数量错误(给定7,预期为4..6) 模型 班级学生

嗨,我一直在关注这个文档

还是没能在我的应用程序上运行

我不断地收到

参数数量错误(给定7,预期为4..6)

模型

班级学生
看法


您不需要:学生

  <%= f.collection_select(:school_degree , SchoolDegree.all, :id, :test, {prompt: 'College Degree'},{class: "form-control"}) %>

你不应该需要:学生

  <%= f.collection_select(:school_degree , SchoolDegree.all, :id, :test, {prompt: 'College Degree'},{class: "form-control"}) %>
试试这个:

将类方法更改为实例方法

class SchoolDegree < ApplicationRecord
   belongs_to :school
   belongs_to :degree
   belongs_to :college
   has_many :students

    def test 
       "#{degree.name} - #{college.name}"
    end    


end
班级学校学位
鉴于,

<%= f.collection_select(:school_degree_id , SchoolDegree.all, :id, :test, {prompt: 'College Degree'},{class: "form-control"}) %>

试试这个:

将类方法更改为实例方法

class SchoolDegree < ApplicationRecord
   belongs_to :school
   belongs_to :degree
   belongs_to :college
   has_many :students

    def test 
       "#{degree.name} - #{college.name}"
    end    


end
班级学校学位
鉴于,

<%= f.collection_select(:school_degree_id , SchoolDegree.all, :id, :test, {prompt: 'College Degree'},{class: "form-control"}) %>

请在下面尝试

<%= f.collection_select :score_id, SchoolDegree.all, :id, :test, { :prompt => 'College Degree'},{ :class => "form-control" } %>
欲了解更多信息,请点击下面的链接

请在下面尝试

<%= f.collection_select :score_id, SchoolDegree.all, :id, :test, { :prompt => 'College Degree'},{ :class => "form-control" } %>
欲了解更多信息,请点击下面的链接

试试这个

class Student < ApplicationRecord
  belongs_to :school_degree

    def test 
          "#{school_degree.degree.name} - #{school_degree.college.name}"

    end
 end
班级学生
试试这个

class Student < ApplicationRecord
  belongs_to :school_degree

    def test 
          "#{school_degree.degree.name} - #{school_degree.college.name}"

    end
 end
班级学生
还是不走运,它给了我“错误数量的参数(假设为0,预期为2..3)”让它正常工作了,非常感谢!两天来,我一直在努力让它工作!仍然没有运气,它给了我“错误数量的参数(假设为0,预期为2..3)”让它工作了,非常感谢!两天来,我一直在努力让它工作!我之前尝试过这个,但运气不好,它一直给我这个错误“错误的参数数量(给定0,预期2..3)”我之前尝试过这个,运气不好,它一直给我这个错误“错误的参数数量(给定0,预期2..3)”