开发者

:method => 'delete' in link_to doesn't seem to work in Rails 3?

开发者 https://www.devze.com 2023-01-12 07:29 出处:网络
I have code like this in a Rails 3 app I\'m working on <% @positions.each do |position|%> <tr class=\"<%= cycle(\"\", \"alternate\") %>\">

I have code like this in a Rails 3 app I'm working on

    <% @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 =&g开发者_如何转开发t; 'Are you sure you want to delete this item?', :method => 'delete' %>
        </td>
    </tr>
    <% end %>

The edit link works fine, but the delete link keeps taking me to the show action.

Any idea what the problem is?

PS: I'm using formtastic in tandem with Mongoid and ActiveRecord isn't loaded in my config/application.rb file.


Rails 3 is using unobstrusive javascript to handle delete so you may need to add the following into your layout:

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>

Check out railscasts 205 to see how to use jquery instead of prototype.

0

精彩评论

暂无评论...
验证码 换一张
取 消