gpt4 book ai didi

ruby-on-rails - Rails 4.1 上具有单表继承的嵌套表单字段

转载 作者:太空宇宙 更新时间:2023-11-03 18:17:53 25 4
gpt4 key购买 nike

我到处搜索,但没有找到任何解决方案。我正在使用具有单表继承的 Rails 4.1 nested_form。我有模型 - suspectsvictims 继承自模型 person。每个警报都有很多嫌疑人和很多受害者提交时,它仅将 alert 数据填充到数据库中,而不是其 nested_attributes。请查看型号名称 alert 及其型号。

作者删除了链接

我得到的是:

Started POST "/alerts" for 127.0.0.1 at 2014-04-25 13:50:26 -0500
Processing by AlertsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"4RHZ6i0eWIWnyYwmick7VlmGouTRiTFciKiQUw/Ea54=", "alert"=>{"victims_attributes"=>{"0"=>{"first_name"=>"", "last_name"=>"", "race"=>"", "gender"=>"", "hair_color"=>"", "eye_color"=>"", "height_ft"=>"", "height_inch"=>"", "age"=>"", "age_unit"=>"", "birth_date"=>"__/__/____", "weight"=>"", "additional_info"=>"", "_destroy"=>"false"}}, "created_at"=>"____/__/__ __:__", "nic"=>"", "investigating_officer_name"=>"", "investigating_officer_title"=>"", "investigating_officer_phone"=>"", "agency_name"=>"", "agency_phone"=>"", "reporting_agency_phone"=>"", "reporting_agency_email"=>""}, "commit"=>"Create Alert"}
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 8 ORDER BY "users"."id" ASC LIMIT 1
(0.0ms) BEGIN
SQL (2.0ms) INSERT INTO "alerts" ("agency_name", "agency_phone", "created_at", "investigating_officer_name", "investigating_officer_phone", "investigating_officer_title", "nic", "reporting_agency_email", "reporting_agency_phone", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id" [["agency_name", ""], ["agency_phone", ""], ["created_at", "2014-04-25 18:50:26.422890"], ["investigating_officer_name", ""], ["investigating_officer_phone", ""], ["investigating_officer_title", ""], ["nic", ""], ["reporting_agency_email", ""], ["reporting_agency_phone", ""], ["updated_at", "2014-04-25 18:50:26.422890"]]
(62.0ms) COMMIT
Redirected to http://127.0.0.1:3000/alerts
Completed 302 Found in 87ms (ActiveRecord: 66.0ms)

但我也期待它的 nested_attributes(使用 STI)嫌疑人、车辆和受害者也被查询,但它没有发生。

任何帮助/建议表示赞赏。

我希望此查询出现两次,一次针对受害者,一次针对嫌疑人。我在日志中没有看到任何错误。

SQL (2.0ms)  INSERT INTO "people" ("additional_info", "age_unit", "alert_id", "created_at", "eye_color", "first_name", "gender", "hair_color", "last_name", "race", "type", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING "id"  [["additional_info", ""], ["age_unit", ""], ["alert_id", 16], ["created_at", "2014-04-25 19:27:29.080890"], ["eye_color", ""], ["first_name", ""], ["gender", ""], ["hair_color", ""], ["last_name", ""], ["race", ""], ["type", "victim"], ["updated_at", "2014-04-25 19:27:29.080890"]]

SQL (2.0ms) INSERT INTO "vehicle" ("additional_info", "age_unit", "alert_id", "created_at", "eye_color", "first_name", "gender", "hair_color", "last_name", "race", "type", "updated_at") .....

最佳答案

发生这种情况是因为您传递了额外的 form 标记,请检查源代码。您不应该在 fields_for 中创建 form 标记。

关于ruby-on-rails - Rails 4.1 上具有单表继承的嵌套表单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23300785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com