0

app/models/encounter.rb

class Encounter < ActiveRecord::Base
  has_many: orders
end

应用程序/模型/order.rb

class Order < ActiveRecord::Base
  belongs_to :encounter
  has_many :order_tests
  has_many :tests, through :order_tests
end

应用程序/模型/order_test.rb

Class OrderTest < ActiveRecord::Base
  belongs_to :order
  belongs_to :test
end

应用程序/模型/test.rb

Class Test < ActiveRecord::Base
  has_many :order_tests
  has_many :orders, through: :order_tests
end

我正在尝试将多个测试添加到给定遭遇的第一个顺序。我试图通过使用 simple_form 关联来实现这一点。这是我在视图中的设置

= simple_form_for @encounter do |f|
  = f.input :name
  = f.patient_id
  = f.doctor_id
  = simple_form_for @encounter.orders.first do |o|
    = o.associations tests, as: :check_boxes, collection: Test.all

这是我的服务器日志

Started PATCH "/encounters/71?next_step=Meds+Entry&step_group=accessioning&task=326" for 127.0.0.1 at 2016-04-05 13:10:50 -0500
Processing by EncountersController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"qSC7IHInq0fqArDXsXbKENSMYM/5B1Ijry4hZ1o6oVtyVb14ECnt95rNX2Pqv+GHmanugkBvQfc686JmKJeSeA==", "encounter"=>{"patient_id"=>"", "organization_id"=>"", "address_id"=>"", "name"=>"", "encounter_type_id"=>"3", "encounter_at"=>"", "do_next_step"=>"0"}, "patient_first_name"=>"", "patient_middle_name"=>"", "patient_last_name"=>"", "patient_dob"=>"", "patient_gender"=>"", "patient_race"=>"", "patient_ssn"=>"", "address"=>"", "city"=>"", "state"=>"", "zip"=>"", "npi"=>"", "order"=>{"test_ids"=>["1", "2", "3", ""]}, "button"=>"", "next_step"=>"Meds Entry", "step_group"=>"accessioning", "task"=>"326", "id"=>"71"}
  CACHE (0.0ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["id", 2]]
  CACHE (0.0ms)  SELECT  "encounters".* FROM "encounters" WHERE "encounters"."id" = $1 LIMIT 1  [["id", "71"]]
  Task Load (0.2ms)  SELECT  "tasks".* FROM "tasks" WHERE "tasks"."deleted_at" IS NULL AND "tasks"."id" = $1 LIMIT 1  [["id", 326]]
   (0.2ms)  BEGIN
   (0.2ms)  COMMIT
   (0.2ms)  BEGIN
   (0.2ms)  COMMIT
Redirected to http://localhost:3002/encounters/71
Completed 302 Found in 45ms (ActiveRecord: 4.5ms)

似乎它没有添加任何记录,我有点不确定如何去做。我正在尝试在order_tests表(order_id,test_id)中为每个选中的复选框添加一条新记录。

4

1 回答 1

0

假设日志剪辑是为了更新遭遇,有一个明显的问题是没有调用更新命令......我正在处理的项目中的随机示例:

  SQL (22.7ms)  UPDATE "users" SET "trust_name" = $1, "updated_at" = $2 WHERE "users"."id" = $3  [["trust_name", "ttrusdt dfsdf"], ["updated_at", "2016-04-05 19:03:26.823849"], ["id", 24]]

这让我相信控制器操作中发生了一些意想不到的事情......发布您的代码可能会有所帮助。

如果它在其他地方失败,比如验证,我希望在日志中看到更新命令,然后是回滚......拒绝更新。

于 2016-04-05T19:16:13.347 回答