懸念/モジュールを使用して、デフォルトの _form.html.erb に collection_select タグを使用しようとしています。いくつかの部門名を含むハッシュを設定する必要があります。
ここに私の app/models/concerns/SetDepartment.rb があります
module Set_Department
extend ActiveSupport :: Concern
def department
department {
1=>"Amatitlán",
2=>"Chinautla",
3=>"Chuarrancho"
}
end
end
department メソッドを呼び出したいモデルは次のとおりです。
class Aplicante < ActiveRecord::Base
include SetDepartment
validates :titulo_id, :primer_nombre,
:primer_apellido, :dpi, :direccion_linea_1,:zona, :department_id, :username,
presence: true
validates :dpi,:username, uniqueness: true
has_secure_password
end
ここで、このハッシュを app/views/applicants/_form.html.erb の collection_select タグに含める必要があります
#...
<div class="field">
<%= f.label :department_id %><br>
<%= f.collection_select :department_id, Aplicante.department, Aplicante.department %>
</div>
#...
明らかに、これは機能しませんが、他に何も考えられません。私はインターネットを検索しましたが、難しい説明が得られ、モジュールを含むものはありません...それは可能ですか?