我是 Rails 新手,我认为这是一个非常简单的问题。
我有一个“任务”列表。当您单击一个任务时,我想更新它在数据库中的行以将其标记为完成(将“状态”列从 0 更改为 1)。
以下是我认为链接的样子:
<td><%= link_to t.name, change_task_status_path(:id => t.id) %>
这是我的 tasks_controller.rb 中的内容:
def change_task_status
@t = Task.find_by_id(params[:id])
@t.status = '1' # 1 = complete
@t.save
render :nothing => true
end
我无法弄清楚如何正确格式化链接!加载视图时出现此错误:
undefined method `change_task_status_path' for #<#<Class:0x3a6c144>:0x3a69d54>
编辑 耙路线显示:
tasks GET /tasks(.:format) tasks#index
POST /tasks(.:format) tasks#create
new_task GET /tasks/new(.:format) tasks#new
edit_task GET /tasks/:id/edit(.:format) tasks#edit
task GET /tasks/:id(.:format) tasks#show
PUT /tasks/:id(.:format) tasks#update
DELETE /tasks/:id(.:format) tasks#destroy
phases GET /phases(.:format) phases#index
POST /phases(.:format) phases#create
new_phase GET /phases/new(.:format) phases#new
edit_phase GET /phases/:id/edit(.:format) phases#edit
phase GET /phases/:id(.:format) phases#show
PUT /phases/:id(.:format) phases#update
DELETE /phases/:id(.:format) phases#destroy
projects GET /projects(.:format) projects#index
POST /projects(.:format) projects#create
new_project GET /projects/new(.:format) projects#new
edit_project GET /projects/:id/edit(.:format) projects#edit
project GET /projects/:id(.:format) projects#show
PUT /projects/:id(.:format) projects#update
DELETE /projects/:id(.:format) projects#destroy