我正在开发的 Rails 3 应用程序中有这样的代码
<% @positions.each do |position| %>
<tr class="<%= cycle("", "alternate") %>">
<td><%= position.name %></td>
<td class="actions">
<%=link_to 'edit', edit_position_path(position), :class => 'edit' %> |
<%=link_to 'delete', position_path(position), :confirm => 'Are you sure you want to delete this item?', :method => 'delete' %>
</td>
</tr>
<% end %>
编辑链接工作正常,但删除链接一直把我带到表演 Action 。
知道问题出在哪里吗?
PS:我将 formtastic 与 Mongoid 结合使用,并且 ActiveRecord 未加载到我的 config/application.rb 文件中。
最佳答案
Rails 3 使用简洁的 javascript 来处理删除,因此您可能需要将以下内容添加到您的布局中:
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
查看 railscasts 205查看如何使用 jquery 而不是原型(prototype)。
关于ruby-on-rails - :method => 'delete' in link_to doesn't seem to work in Rails 3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3537228/