Note that there are some explanatory texts on larger screens.

plurals
  1. POParams Passed not Saving from Sortable Nested Form
    text
    copied!<p>So I'm using jquerys sortable to sort nested form fields. Here's controller method it's submitting to when it's sorted:</p> <pre><code>def sort_questions params[:questions_attributes].to_a.each_with_index do |id, index| question = Question.find(id) question.position = index + 1 question.save(:validate =&gt; false) end render :nothing =&gt; true end </code></pre> <p>Here's the params that get passed by looking at my inspector in Chrome:</p> <pre><code> "questions_attributes"=&gt;{"1"=&gt;{"content"=&gt;"Where did you grow up?", "position"=&gt;"", "_destroy"=&gt;"false", "id"=&gt;"2"}, "0"=&gt;{"content"=&gt;"What are you doing?", "position"=&gt;"", "_destroy"=&gt;"false", "id"=&gt;"3"}} </code></pre> <p>Here's the the jquery sortable function that's being called:</p> <pre><code> $('#questions').sortable({ items:'.fields', placeholdet: true, axis:'y', update: function() { $.post("/templates/#{@template.id}/sort_questions?_method=post&amp;" + $('.edit_template').serialize()); } }); </code></pre> <p>The position attribute is not saving. I've tried all kinds of variations of the sort_questions method over and over again with no luck.</p> <p>Any help would be great. Thanks!</p> <p>Here's the full params:</p> <pre><code>"template"=&gt;{"name"=&gt;"Long Term Volunteer Opportunity", "description"=&gt;"This template will be for opportunities that are for long term missionaries.", "default"=&gt;"1", "questions_attributes"=&gt;{"0"=&gt;{"content"=&gt;"What are you doing?", "position"=&gt;"", "_destroy"=&gt;"false", "id"=&gt;"3"}, "1"=&gt;{"content"=&gt;"Where did you grow up?", "position"=&gt;"", "_destroy"=&gt;"false", "id"=&gt;"2"}}} </code></pre>
 

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