我需要同时更新卡片模型的所有记录。我使用map函数获取每张卡的数据,然后使用和AJAX请求发送数据。
var cards = ui.item.parent('.js-CardsContainer .js-CardContainer').map(function() {
return {
list_id: $(this).closest('.js-List').data('id'),
order: $(this).index
}
}).get();
$.ajax({
url: "/cards/",
type: "PATCH",
data: { cards: cards },
success: function(resp){
}
});
我不知道如何使用rails处理这些数据。我的卡片控制器中的哪个动作可以放入逻辑?这个逻辑应该是什么样的?
我想我需要这样的东西......
def index
cards.each(&:save!)
end
显然这是不正确的。有人可以帮忙吗?
以下是发送数据时的日志输出:
Started PATCH "/cards/" for ::1 at 2017-01-06 21:57:05 +0000
ActionController :: RoutingError(没有路由匹配[PATCH]" / cards"):
actionpack(5.0.0.1)lib / action_dispatch / middleware / debug_exceptions.rb:53:in call'
web-console (3.4.0) lib/web_console/middleware.rb:135:in
call_app'
web-console(3.4.0)lib / web_console / middleware.rb:28:in block in call'
web-console (3.4.0) lib/web_console/middleware.rb:18:in
catch'
web-console(3.4.0)lib / web_console / middleware.rb:18:in call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in
call'
railties(5.0.0.1)lib / rails / rack / logger.rb:36:in call_app'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in
阻止通话'
activesupport(5.0.0.1)lib / active_support / tagged_logging.rb:70:in block in tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in
已标记'
activesupport(5.0.0.1)lib / active_support / tagged_logging.rb:70:in tagged'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in
call'
sprockets-rails(3.2.0)lib / sprockets / rails / quiet_assets.rb:13:in call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in
call'
rack(2.0.1)lib / rack / method_override.rb:22:in call'
rack (2.0.1) lib/rack/runtime.rb:22:in
call'
activesupport(5.0.0.1)lib / active_support / cache / strategy / local_cache_middleware.rb:28:in call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in
call'
actionpack(5.0.0.1)lib / action_dispatch / middleware / static.rb:136:in call'
rack (2.0.1) lib/rack/sendfile.rb:111:in
call'
railties(5.0.0.1)lib / rails / engine.rb:522:在call'
puma (3.6.2) lib/puma/configuration.rb:225:in
电话'
puma(3.6.2)lib / puma / server.rb:578:在handle_request'
puma (3.6.2) lib/puma/server.rb:415:in
process_client'
puma(3.6.2)lib / puma / server.rb:275:在block in run'
puma (3.6.2) lib/puma/thread_pool.rb:116:in
块中的spawn_thread'
渲染/Users/colmtuite/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb
渲染/Users/colmtuite/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb
呈现/Users/colmtuite/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb(1.8ms)
呈现/Users/colmtuite/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb(30.8ms)