我有一个链接可以切换数据库中属性的真/假。我有两个版本的这个链接的两个不同的属性,一个工程,另一个不,除非我强制一个特定的ID它工作正常。Ruby Rails:控制器没有正确传递ID?
工作链接查看:
<h1><%= link_to "Toggle True", toggle_completed_true_task_path(@task), :remote => true %></h1>
<h1><%= link_to "Toggle False", toggle_completed_false_task_path(@task), :remote => true %></h1>
工作负责人的观点:
respond_to :html, :js
def toggle_completed_true
@task = Task.find(params[:id])
@task.update_attributes(:completed => true)
end
respond_to :html, :js
def toggle_completed_false
@task = Task.find(params[:id])
@task.update_attributes(:completed => false)
end
失败的链接查看:
<h1><%= link_to "Toggle True", toggle_confirmed_true_task_path(@task), :remote => true %></h1>
<h1><%= link_to "Toggle False", toggle_confirmed_false_task_path(@task), :remote => true %></h1>
出现故障的控制器的观点:
respond_to :html, :js
def toggle_confirmed_true
@task = Task.find(params[:id])
@task.update_attributes(:confirmed => true)
end
respond_to :html, :js
def toggle_confirmed_false
@task = Task.find(params[:id])
@task.update_attributes(:confirmed => false)
end
我一直在这工作了几个小时,对我的生活我看不出为什么一个应该失败,另一个工作。 注这两个出现在同一个页面,不工作,如果我在一个特定的ID通过像这样将工作的一个上:
<h1><%= link_to "Toggle True", toggle_confirmed_true_task_path(12), :remote => true %></h1>
特定的错误我与可变通得到的是: “没有路由匹配{:action =>”toggle_confirmed_true“,:controller =>”tasks“,:id => nil”
任何洞察力都非常感谢。
你还记得把它添加到你的routes.rb文件吗? – MrDanA
我的回答帮助@Nathan? – MrYoshiji