Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Taking a look at the params in your trace, I think the form may be incorrect in some way, but it's hard to say how without a little more information. The params you're getting from the form right now are (reformated for legibility):</p> <pre><code>{ "commit" =&gt; "Send message", "_method" =&gt; "put", "machine_enquiry" =&gt; { "messages_attributes" =&gt; { "message" =&gt; "2", "title" =&gt; "1", "message_type_id" =&gt; "1", "contact_detail_ids" =&gt; [ "1", "11" ] } }, "id" =&gt; "2", "datetime" =&gt; "" } </code></pre> <p>But they should look something like:</p> <pre><code>{ "commit" =&gt; "Send message", "_method" =&gt; "put", "machine_enquiry" =&gt; { "messages_attributes" =&gt; { 0 =&gt; { "message" =&gt; "2", # this may still be wrong "title" =&gt; "1", "message_type_id" =&gt; "1", "contact_detail_ids" =&gt; [ "1", "11" ] } } }, "id" =&gt; "2", "datetime" =&gt; "" } </code></pre> <p>Note that the hash that was directly inside of <code>messages_attributes</code> is now a level deeper. The nested attributes section of the form should contain a hash with a unique key for each message that is being created or edited. The source of the error was that the form format parser was seeing <code>message</code>, <code>title</code>, <code>message_id</code>, and <code>contact_detail_ids</code> as the unique keys for four separate messages, but the values associated with those keys weren't hashes, as it expected.</p> <p>The line I've called out with a comment in the corrected example I'm a little unsure of. Without seeing the form in its entirety or the <code>Message</code> class, it's hard to know if that's an attribute of the message, or maybe it's supposed to be the message id. The message id, by the way, should be included only if you're editing an existing message.</p> <p>There's an <a href="http://wonderfullyflawed.com/2009/02/17/rails-forms-microformat/" rel="nofollow noreferrer">exhaustive explanation of the Rails forms micro-format</a> available. Search for <code>has_many</code> to find the relevant section.</p> <p>The source of this mis-formatted params hash is almost certainly your <code>form_for</code>. If you include the entirety of it, someone may be able to help you diagnose why the form is being created incorrectly.</p> <hr> <p><strong>Updated</strong></p> <p>After looking at your full form, the problem is this line:</p> <pre><code>&lt;% me_form.fields_for :messages_attributes do |f| %&gt; </code></pre> <p>It should read:</p> <pre><code>&lt;% me_form.fields_for :messages do |f| %&gt; </code></pre> <p>The <code>fields_for</code> helper expects the association name in order to act correctly. Another problem I saw while looking at the form is the radio buttons that you use for contacts will need to have the <code>name</code> changed as well to something like <code>machine_enquiry[messages_attributes][0][contact_detail_ids][]</code>. You'll probably need to find a way to generate those radio buttons using the form helper so they can get the correct message id.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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