Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:05:16+00:00 2026-06-04T21:05:16+00:00

I have a jquery sortable calling a data-update-url in my model controller, everything is

  • 0

I have a jquery sortable calling a data-update-url in my model controller, everything is good and the function is getting called.
my sort function

def sort
        params[:documents].each_with_index do |id, index|
            Document.update_all({position: index+1}, {id: id})
        end
        render nothing: true
    end

Now i’m using mongoid and I know there isn’t exactly as flexible way to do what I want as you can in SQL. After a user drags an element in the list the way he wants, I want the positon to update so the order of the users list is persistent through sessions.
The above function was a template I started so I can start in the right direction (from railscasts)
My first problem is the params[:documents].each_with_index, im gettting thrown a

NoMethodError (undefined method `each_with_index' for nil:NilClass):
  app/controllers/documents_controller.rb:16:in `sort'

So i’m sure params[:document] isn’t what i want to pass to the each_with_index method but i’m unsure what to try?

update
document.js.coffee

jQuery ->
  $('#documents').sortable(
    update: ->
      $.post($(this).data('update-url'), $(this).sortable('serialize')));

corresponding erb

<ul id="documents" data-update-url="<%= sort_documents_url %>">
  <% @documents.each do |document| %>
    <%= content_tag_for :li, document do %>
      <%= render document %>
    <% end %>
  <% end %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:05:17+00:00Added an answer on June 4, 2026 at 9:05 pm
    def sort
        params[:documents].each_with_index do |id, index|
          doc = Document.find_by_id(id)
          doc.update_attribute(:position, index) if doc
        end
        render nothing: true
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery sortable with an ajax callback tied to the update event.
I have a table whose body I've made sortable using jQuery UI's Sortable function.
I have the following ListView in which I am using the JQuery UI sortable
I'm working with a demo of two sortable jquery lists... but have a problem
I'm trying to follow http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/ And have created a very simple example http://jsfiddle.net/6wbZQ/ It's
i have atext from jquery method : <fieldset> <ul id=ContentPlaceHolder2_1g class=profList column ui-sortable> <legend
I have multiple JQuery sortable lists that connect with each other... They allow you
I have a jQuery UI Sortable list. The sortable items also have a click
Little help need with jquery sortable. I have a nested list like so: <div
I am looking for a method to have a JQuery-like sortable list ( link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.