Note that there are some explanatory texts on larger screens.

plurals
  1. PO"NoMethodError (undefined method `with_indifferent_access' for..." when passing it nested attributes
    primarykey
    data
    text
    <p>Been googling this for a while and having no luck. I'm getting an "NoMethodError (undefined method `with_indifferent_access'" error on my web service when passing it nested attributes. </p> <p>Other nested ones work, they are one-to-one however and this is one-to-many...</p> <pre><code>class Customer &lt; ActiveRecord::Base belongs_to :quote has_one :policy, :dependent =&gt; :destroy has_one :vehicle, :dependent =&gt; :destroy has_many :claims, :dependent =&gt; :destroy has_many :incidents, :dependent =&gt; :destroy accepts_nested_attributes_for :policy accepts_nested_attributes_for :vehicle accepts_nested_attributes_for :incidents end </code></pre> <p>Working correctly:</p> <pre><code> Processing QuotesController#create to xml (for 127.0.0.1 at 2010-12-12 15:16:33) [POST] Parameters: {"quote"=&gt;{"customer_attributes"=&gt;{"address1"=&gt;nil, "city"=&gt;"ggh", "dob"=&gt;nil, "address2"=&gt;nil, "title"=&gt;nil, "country"=&gt;nil, "postcode"=&gt;nil, "vehicle_attributes"=&gt;{"mileage"=&gt;nil, "registration"=&gt;nil, "value"=&gt;nil, "parking"=&gt;nil}, "policy_attributes"=&gt;{"breakdown"=&gt;nil, "windscreen"=&gt;"1", "excess"=&gt;nil}, "telephone"=&gt;nil, "surname"=&gt;nil, "forename"=&gt;"wasdddfggh", "email"=&gt;nil}}} [4;35;1mQuote Create (1.0ms)[0m [0mINSERT INTO "quotes" ("created_at", "updated_at") VALUES('2010-12-12 15:16:33', '2010-12-12 15:16:33')[0m [4;36;1mCustomer Create (0.0ms)[0m [0;1mINSERT INTO "customers" ("address1", "city", "dob", "address2", "quote_id", "created_at", "title", "country", "postcode", "updated_at", "telephone", "forename", "surname", "email") VALUES(NULL, 'ggh', NULL, NULL, 2, '2010-12-12 15:16:33', NULL, NULL, NULL, '2010-12-12 15:16:33', NULL, 'wasdddfggh', NULL, NULL)[0m [4;35;1mPolicy Create (0.0ms)[0m [0mINSERT INTO "policies" ("breakdown", "created_at", "windscreen", "excess", "updated_at", "customer_id") VALUES(NULL, '2010-12-12 15:16:33', 1, NULL, '2010-12-12 15:16:33', 2)[0m [4;36;1mVehicle Create (0.0ms)[0m [0;1mINSERT INTO "vehicles" ("mileage", "created_at", "updated_at", "registration", "value", "parking", "customer_id") VALUES(NULL, '2010-12-12 15:16:33', '2010-12-12 15:16:33', NULL, NULL, NULL, 2)[0m Completed in 153ms (View: 4, DB: 1) | 201 Created [http://localhost/quotes.xml] host/quotes.xml] </code></pre> <p>However, when adding</p> <pre><code>"incidents_attributes"=&gt;{"date_of_incident"=&gt;"2008-05-19", "sum_of_claim"=&gt;"34554", "description"=&gt;"PLEASE!"}, </code></pre> <p>it causes</p> <pre><code>NoMethodError (undefined method `with_indifferent_access' for "2008-05-19":String): </code></pre> <p>Removing the date_of_incident and it will just complain the same about the next attribute.</p> <p>Previously I had "incident_attributes" (singular incident) and has_many :incident, but changing this didn't help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload