无法调用不删除RoR的HTTP删除方法

时间:2012-03-23 18:21:23

标签: ruby-on-rails-3

我正在关注一个教程,我正在尝试调用这样的删除方法:

用户/ index.html.erb中的

我得到了:

<!-- View for index action in user's controleer -->
<h1>All users - Administration Page</h1>

<%= will_paginate %>

<ul class="users">
  <% @users.each do |user| %>
    <li>
      <%= link_to user.name, user %>
      <!-- if the current user is admin -->
        <% if current_user.admin? && !current_user?(user) %>
            | <%= link_to "delete", user, method: :delete, confirm: "You sure?" %>
        <% end %>
    </li>
  <% end %>
</ul>

<%= will_paginate %>

在我的用户控制器中我得到了这个:

  #destroying users!
  def destroy
    User.find(params[:id]).destroy
    flash[:success] = "User destroyed."
    redirect_to users_path
  end

而不是收到确认框,我被重定向到用户的个人资料?! 看来rails服务器无法读取我发送给它的删除方法!

编辑: 耙路线:

rake routes
intergration_test_authentication_pages GET    /intergration_test/authentication_pages(.:format) intergration_test#authentication_pages
                                  root        /                                                 static_pages#home
                          user_profile        /user_profile(.:format)                           users#show_user
                            all_videos        /all_videos(.:format)                             static_pages#allvideos
                        show_interface        /show_interface(.:format)                         static_pages#interface
                                 users GET    /users(.:format)                                  users#index
                                       POST   /users(.:format)                                  users#create
                              new_user GET    /users/new(.:format)                              users#new
                             edit_user GET    /users/:id/edit(.:format)                         users#edit
                                  user GET    /users/:id(.:format)                              users#show
                                       PUT    /users/:id(.:format)                              users#update
                                       DELETE /users/:id(.:format)                              users#destroy
                              sessions POST   /sessions(.:format)                               sessions#create
                           new_session GET    /sessions/new(.:format)                           sessions#new
                               session DELETE /sessions/:id(.:format)                           sessions#destroy
                                signup        /signup(.:format)                                 users#new
                                signin        /signin(.:format)                                 sessions#new
                               signout        /signout(.:format)                                sessions#destroy

2 个答案:

答案 0 :(得分:0)

您很可能没有在您的网页上添加必要的jQuery UJS Javascript。这是允许:method参数正常工作的原因。

答案 1 :(得分:-1)

我在link_to的语法中看到了一些问题。尝试更新此部分: :method =&gt; :delete,:confirm =&gt; “你确定吗?”