admin管理员组文章数量:1434929
I have the following jQuery sortable code:
$( ".list" ).sortable({
update: function(){
$.ajax({
url: '/books/sort',
type: 'post',
items: 'li',
data: $('.list').sortable('serialize'),
dataType: 'script',
plete: function(request){
alert("jjjj");
}
});
}
});
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})
end
render nothing: true
end
but I get the error:
ArgumentError (wrong number of arguments (2 for 1)):
app/controllers/books_controller.rb:28:in `block in sort'
I have the following jQuery sortable code:
$( ".list" ).sortable({
update: function(){
$.ajax({
url: '/books/sort',
type: 'post',
items: 'li',
data: $('.list').sortable('serialize'),
dataType: 'script',
plete: function(request){
alert("jjjj");
}
});
}
});
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})
end
render nothing: true
end
but I get the error:
ArgumentError (wrong number of arguments (2 for 1)):
app/controllers/books_controller.rb:28:in `block in sort'
Share
Improve this question
asked Dec 25, 2014 at 20:42
MuhambiMuhambi
3,5226 gold badges33 silver badges57 bronze badges
1
-
1
Book.update_all({position: (index+1), id: id})
– adeneo Commented Dec 25, 2014 at 20:44
2 Answers
Reset to default 5If someone lands here wondering the same thing, the reason why you get "Wrong number of arguments" it's cause there was a change in Rails (I believe it was on 4.0) that moved the section where you specify the condition.
So, for this to work, you'd have to use something like this:
def sort
params[:book].each_with_index do |id, index|
Book.where(id: id).update_all({position: index+1})
end
render nothing: true
end
And everything else will work as expected.
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.
本文标签: javascriptWrong number of arguments issueStack Overflow
版权声明:本文标题:javascript - Wrong number of arguments issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745632341a2667349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论