1

作为任务管理应用程序用户,我想单击任务上的“已完成”链接以将任务的解决方案记录为已完成。

我希望这是一个使用 Rails 3 方式的 Unobtrusive JavaScript (UJS) 的 AJAX 请求。我已经调试了很长时间了,所以任何帮助都将不胜感激。

这是我在视图中进行的 link_to 调用:

<%= link_to "Completed", task_path(:id => task.id, :resolution => "completed"), :remote => true, :method => :put %>

这是我的任务控制器中的更新方法:

class TasksController < ApplicationController
  respond_to :js

  def update
    @task = Task.find(params[:id])
    @task.update_attributes(params[:task])
    respond_with(@task)
  end
end

使用 Chrome 的开发工具观察网络流量,似乎正在向正确的 URL 发出 Put 请求,包括 URL 参数 (tasks/{:id}?resolution=completed),但预览显示以下错误消息:

Template is missing

Missing template tasks/update, application/update with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. 

Searched in: * "C:/Documents and Settings/Corey Quillen/My Documents/Software Engineering/Projects/Cleaner Card/cleaner_card/app/views"
4

2 回答 2

2

您需要将分辨率作为任务的属性 - 然后它将更新:

<%= link_to "Completed", task_path(:id => task.id, "task[resolution]" => "completed"), :remote => true, :method => :put %>

在 rails 4 - 首选方法是 :patch 进行更新。

于 2014-02-20T16:11:35.443 回答
0

您需要在 中处理更新方法的响应update.js.erb

将该文件放在app/views/tasks/update.js.erb.

于 2013-05-18T19:40:17.910 回答