我是新来的铁轨,我有我认为是一个非常简单的问题。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>
编辑 耙路线显示:
resources :tasks do
member do
get :change
end
end
它将:
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
运行'rake routes'来查看你的路由名称实际上是什么。 – MrDanA
我编辑我的问题以显示我的耙路线响应。这条道路似乎根本没有出现。 – nathan
试着看看这个链接了解更多信息:http://guides.rubyonrails.org/routing.html。当您添加控制器操作时,您不会自动访问它。你必须在你的routes.rb文件中定义它。然后,根据你如何定义它,它将决定你的助手链接的样子。 – MrDanA