Muhambi Muhambi - 1 year ago 57
Ruby Question

Wrong number of arguments issue

I have the following jQuery sortable code:

$( ".list" ).sortable({
update: function(){
url: '/books/sort',
type: 'post',
items: 'li',
data: $('.list').sortable('serialize'),
dataType: 'script',
complete: function(request){

and a sort action in my controller like:

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

but I get the error:

ArgumentError (wrong number of arguments (2 for 1)):
app/controllers/books_controller.rb:28:in `block in sort'

Answer Source

Do as below

Book.where(id: id).
  update_all(position: index+1)

If you read the documentation, it says explicitly :-

Parameters :

updates - A string, array, or hash representing the SET part of an SQL statement.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download