simple_form_for 中 association 的使用

simple_form_for 中 association 的使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# model
class Question < ApplicationRecord
has_many :invitated_users, through: :question_invitations, source: :user
end
# html
<%= f.association :invitated_users, :as => :check_boxes, label: false,selected: @question.invitated_users %>
# controller
# strong params 中加入
params.require(:question).permit(:invitated_user_ids=>[] )
即可自动保存关系