我有一个Rails 2.3.18应用程序,允许用户将项目拖放到列表中。当用户拖放时,我收到以下错误:
ActionView::MissingTemplate (视图路径中缺少模板列表/sorting.erb)
下面是相关的javascript。我知道Rails正在寻找一个模板,但我不确定我应该将用户指向什么,因为我希望他们只停留在页面上,但能够在他们的列表中工作。对不起,我太缺乏经验了!
// Lists Sorting
$('#items').sortable({
stop: function() {
$.post('/lists/sorting', { item_sort: $('#items').sortable('serialize') });
}
});
发布于 2016-10-15 04:39:04
我可以假设您有带有排序方法的lists_controller。在您的示例中,您的请求缺少视图文件。它实际上是一个Ajax请求,因此一旦您在视图/列表路径中添加sorting.js.erb文件,它将被解析。
发布于 2016-10-15 04:53:39
由于您使用了$.post('/lists/sorting')
,我假设控制器中有listing controller
和sorting
方法。
如果您想使用ajax请求而不想要erb
文件,只需使用json
响应即可。如果使用json响应,rails将不会搜索erb
文件,
在你的控制器里试试这个。
class ListsController < ApplicationController
def sorting
@lists = List.find(params[:id]) // Your line here
render json: @lists
end
end
现在,这个json
响应将返回给ajax调用。
https://stackoverflow.com/questions/40054231
复制相似问题