我到處搜索,但沒有找到任何解決方案。我正在使用Rails 4.1 nested_form和單表繼承。 我有型號 - suspects
和victims
繼承自型號person
。 每個alert
有許多suspects
和許多victims
提交時,它只填充alert
數據到數據庫中,但不填充它的nested_attributes。請參閱型號名稱alert
及其型號。通過筆者在Rails 4.1上使用單表繼承的嵌套表單字段
刪除鏈接什麼,我得到的是:
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") .....
您沒有在表單中傳遞任何受害者或嫌疑人數據。由於'suspects_attributes'完全缺失,且'victim_attributes'中所有鍵的值都爲空(「」)。那麼,問題是什麼? –
Kirti,我輸入了所有屬性的數據,但它根本不會填充到數據庫表中。 – jimagic
Kirti,我不知道究竟是什麼意思?即使你沒有通過任何東西,它仍然會將數據視爲空白並堅持數據庫。我輸入了所有數據並創建了可疑,受害者,並且車輛不會在數據庫中持續存在,但警報的所有屬性都會持續存在。 – jimagic