我正在尝试调用自定义方法,让我们说'get_divisions_by_school_id'并将变量传递给simple_form_for中的该方法
而不是:divisions,我想在以下代码中调用:get_divisions_by_school_id(@ school.id):
<%= f.grouped_collection_select(:division_id, @teacher.standards, :divisions, :id, :id, :name, {:class => "input-box-width1", :required => true},{:multiple=>true}) %>
我想要类似的东西:
<%= f.grouped_collection_select(:division_id, @teacher.standards, :get_divisions_by_school_id(@school.id), :id, :id, :name, {:class => "input-box-width1", :required => true},{:multiple=>true}) %>
答案 0 :(得分:0)
您可以创建一个获取学校ID的类方法并执行以下操作:
class Teacher < ActiveRecord::Base
def self.get_divisions_by_school_id(school_id)
# Foobarbaz.
end
end
并使用它:
<%= f.grouped_collection_select(:division_id, @teacher.standards, Teacher.get_divisions_by_school_id(@school.id), :id, :id, :name, {:class => "input-box-width1", :required => true},{:multiple=>true}) %>