Question

I search everywhere but did not found any solution. I am using Rails 4.1 nested_form with Single table inheritance. I have model - suspects and victims inherited from model person. Each alert have many suspects and many victims On submit, it only populate alert data into database but not its nested_attributes. Please see model name alert and its model.

removed link by author

what I am getting is:

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)

but I am also expecting its nested_attributes (using STI) suspects, vehicles and victims on query too, but its not happening.

any helps/suggestions appreciate.

I am expecting this query to show up twice One for Victim and one for Suspect. I am not seeing any error on log.

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") .....
Was it helpful?

Solution

It is occurring because you are passing additional form tag, check the source code. You are not suppose to create form tag inside fields_for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top