データベース内の属性の true/false を切り替えるリンクがあります。特定のIDを強制する場合を除いて、2つの異なる属性に対してこのリンクの2つのバージョンがあります.1つは機能し、もう1つは機能しません。
作業リンクのビュー:
<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>
変数パスで発生する特定のエラーは次のとおりです。
どんな洞察も大歓迎です。