Ruby on rails ActionController::RoutingError:没有与之匹配的路由->;使用复选框时+;AJAX
我正在构建一个简单的任务管理应用程序,当我尝试处理复选框以指示任务已完成时,会出现一个奇怪的问题 下面是我想到的代码:Ruby on rails ActionController::RoutingError:没有与之匹配的路由->;使用复选框时+;AJAX,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我正在构建一个简单的任务管理应用程序,当我尝试处理复选框以指示任务已完成时,会出现一个奇怪的问题 下面是我想到的代码: <%= check_box_tag "id", "id", task.done, :onclick => remote_function( :update => "task", :url => { :action => :update, :controller => :tasks, :id => ta
<%= check_box_tag "id", "id", task.done,
:onclick => remote_function(
:update => "task",
:url => { :action => :update, :controller => :tasks, :id => task.id },
:with => "'task[done]=true'",
:complete => "alert('hi')" ) %>
你能帮我找出我做错了什么吗?为什么找不到路线
以下是\u task.html.erb视图的完整代码
<tr>
<td class="task">
<span class="tasktitle">
<%= check_box_tag "id", "id", task.done,
:onclick => remote_function(
:update => "task",
:url => { :action => :update, :controller => :tasks, :id => task.id },
:with => "task[done]=true",
:complete => "alert('hi')" ) %>
<span class="<%= if (task.done) then "editable_field_complete" else "editable_field" end %>" id="task_title_<%= task.id %>">
<%= best_in_place task, :title, :type => :input %>
</span>
</span>
<span class="taskdelete"><%= link_to "delete", task, :method => :delete, :class => "delete",
:confirm => "You sure?",
:title => task.title %></span>
<span class="taskcreated">
Created <%= time_ago_in_words(task.created_at) %> ago.
</span>
</td>
</tr>
遥控功能(
:update=>“任务”,
:url=>{:action=>:update,:controller=>:tasks,:id=>task.id},
:with=>“任务[完成]=true”,
:complete=>“警报('hi')”)%>
:输入%>
:delete,:class=>“delete”,
:confirm=>“确定吗?”,
:title=>task.title%>
创建于20年前。
非常感谢各位问题似乎在于远程_函数使用POST协议提交数据,但当您在routes.rb中使用资源时,它在调用更新操作时仅接受PUT协议 尝试将以下参数添加到远程函数:
:method=>:put
因此,最终结果将是:
<%= check_box_tag "id", "id", task.done,
:onclick => remote_function(
:update => "task",
:url => { :action => :update, :controller => :tasks, :id => task.id },
:method => :put,
:with => "task[done]=true",
:complete => "alert('hi')" ) %>
remote\u功能(
:update=>“任务”,
:url=>{:action=>:update,:controller=>:tasks,:id=>task.id},
:method=>:put,
:with=>“任务[完成]=true”,
:complete=>“警报('hi')”)%>
<%= check_box_tag "id", "id", task.done,
:onclick => remote_function(
:update => "task",
:url => { :action => :update, :controller => :tasks, :id => task.id },
:method => :put,
:with => "task[done]=true",
:complete => "alert('hi')" ) %>