ActiveAdmin,datetime&强参数

时间:2014-07-06 01:46:20

标签: ruby-on-rails ruby-on-rails-4 activeadmin

我有一个名为' Trainers'使用名为scheduled_interview的日期时间字段,可在ActiveAdmin中编辑:

f.input :scheduled_interview

这会产生5 <select>秒(年,月,日,小时和分钟)。

我尝试过添加以下内容:

permit_params :scheduled_interview => []

permit_params scheduled_interview: []

进入ActiveAdmin.register Trainer do ...

但是在提交表格时,我看到了:

Unpermitted parameters: scheduled_interview(1i), scheduled_interview(2i), scheduled_interview(3i), scheduled_interview(4i), scheduled_interview(5i)

我对强参数做错了什么?

编辑1:这是使用Rails 4,我并不清楚。

编辑2:

在训练师控制器中:

def create
  @trainer = Trainer.new(application_params)
end

def application_params
  params.require(:trainer).permit(
    :name, :email, :scheduled_interview: []
  )
end

仅使用:scheduled_interview会产生与上述相同的错误。

编辑3:

保存培训师时记录:

Started PATCH "/admin/prospective_trainers/trainer-id" for 10.0.2.2 at 2014-07-06 17:49:36 +0000
Processing by Admin::ProspectiveTrainersController#update as HTML
  Parameters: {"utf8"=>"✓", "prospective_trainers"=>{"name"=>"trainer name", "email"=>"email@emailaddres.com", "scheduled_interview(1i)"=>"2014", "scheduled_interview(2i)"=>"7", "scheduled_interview(3i)"=>"15", "scheduled_interview(4i)"=>"16", "scheduled_interview(5i)"=>"15"}, "commit"=>"Update Trainer", "id"=>"trainer-id"}
  AdminUser Load (1.2ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 8 ORDER BY "admin_users"."id" ASC LIMIT 1
  Trainer Load (1.2ms)  SELECT "trainers".* FROM "trainers" WHERE "trainers"."slug" = 'trainer-id' ORDER BY "trainers"."id" ASC LIMIT 1
Unpermitted parameters: scheduled_interview(1i), scheduled_interview(2i), scheduled_interview(3i), scheduled_interview(4i), scheduled_interview(5i)
Unpermitted parameters: utf8, _method, commit, id
   (0.4ms)  BEGIN
   (0.4ms)  COMMIT
Redirected to http://localhost:3000/admin/prospective_trainers/trainer-id
  Trainer Load (1.0ms)  SELECT "trainers".* FROM "trainers" WHERE "trainers"."id" = $1 LIMIT 1  [["id", 327]]
Completed 302 Found in 167ms (ActiveRecord: 4.3ms)

所有其他字段保存得很好(姓名,电子邮件等)。

2 个答案:

答案 0 :(得分:1)

解决:在ActiveAdmin的trainer.rb内我错误地放置了2 permit_params,第二个覆盖了第一个ActiveAdmin.register Trainer, as: "Prospective Trainers" do permit_params :name, :email, :scheduled_interview 。修正如下:

:scheduled_interview

还从我的教练控制器的params.require(:trainer).permit(...中删除了{{1}},因为它与ActiveAdmin没有任何关系。

答案 1 :(得分:0)

您需要将:scheduled_interview添加到Trainers控制器。不是ActiveAdmin。 ActiveAdmin只是通过您的常规模型和控制器,它不是分配参数的正确位置。