0
在html中,我有2个使用.column类的div。所以,我创建了一个每个循环来序列化每个.column div的数据。使用rails处理双重post请求
// item.js
$('.column').each(function(){
update: $.post($(this).data('update-url'), $(this).sortable('serialize'));
});
实例是item[]=1&item[]=5&item[]=4
和item[]=2&item[]=3
。这些参数将被发送到rails控制器,通过POST进行排序。
虽然在轨控制器
def sort
params[:item].each_with_index do |id, index|
Item.where(_id: id.last).update(position: index+1)
#Item.where(_id: id.last).update(position: index+4)
end
render nothing: true
end
问:如何处理在干燥方法后的参数?对于第一个请求(item[]=1&item[]=5&item[]=4
),我想用position: index+1
更新数据库(mongoid),而第二个请求我想用position: index+4
更新。谢谢。
一个新的参数(例如'request_type')还是有两个不同的动作? –
它的作品,但它会是丑陋的? – shinnyx
说实话,你在做什么看起来有点丑陋。 :)您也可以将增量作为参数发送(1或4)。 –