1

我正在尝试调用自定义方法让我们说'get_divisions_by_school_id'并将变量传递给simple_form_for中的该方法

我想在以下代码中调用 :get_divisions_by_school_id(@school.id) 而不是 :divisions:

<%= 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}) %>
4

1 回答 1

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}) %>
于 2014-07-22T14:54:24.647 回答