如何在活动管理员中将一个模型的记录分配给另一个关联的记录?



我有一个应用程序,它将申请人注册为Participants,然后将他们分配给Groups。这两个模型通过has_and_belongs_to_many关系相关联。 还有其他与Participant相关的悬挂模型,但它们没有连接到Groups

我希望能够在活动管理员中创建新Group时为Group分配Participant

我的两个模型通过名为 matchups 的联接表连接。

我的Group模型架构如下:

    create_table "groups", force: :cascade do |t|
t.string   "description"
t.integer  "participant_id"
t.datetime "created_at",     null: false
t.datetime "updated_at",     null: false
t.index ["participant_id"], name: "index_groups_on_participant_id"
   end

我的Participant模型架构如下:

    create_table "participants", force: :cascade do |t|
t.string   "first_name"
t.string   "last_name"
t.date     "birthdate"
t.string   "email"
t.string   "phone"
t.string   "street_name"
t.string   "city"
t.string   "state"
t.string   "zip"
t.string   "role"
t.datetime "created_at",  null: false
t.datetime "updated_at",  null: false
t.string   "gender"
   end 

我的活动管理员资源允许以下参数:对于Groups

    permit_params :id, :description, :participant_id, :student_detail_id, :volunteer_detail_id

对于Participants

    permit_params :id, :first_name, :last_name, :gender, :email, :birthdate, :phone, :street_name, :city, :state, :zip, :role

当我在活动管理员中创建新Group时,我唯一能够填写的字段是:d描述。

我想将新组分配给一个或多个 :p articipant_id。

admin/groups.rb编写一个自定义表单以接受多个participant_ids如下所示

ActiveAdmin.register Group do
permit_params :description , participant_ids: []
  form do |f|
    f.inputs 'Group Details' do
      f.input :description
      f.input :participant_ids, as: :check_boxes, collection: Participant.all
     end
  end
end

我没有足够的声誉来评论您的帖子,所以我会提出我的问题作为答案,稍后再编辑。

您能否检查服务器日志并查看正在向创建操作发送哪些数据?如果我不得不猜测,participant_id永远不会被发送。

最新更新