Rails一直说删除路由不存在

时间:2013-08-15 11:31:05

标签: ruby-on-rails

Rails一直说到我的users_controller#destroy的路由不存在?

这是标记:

 = button_to 'Delete', user_path(@user), method: :delete, confirm: 'Are you sure?', class: 'small button delete'

以下是来自routes.rb的摘录:

resources :users, except: [:show]

以下是users_controllers.rb的摘录:   #DELETE / users / 1

 def destroy
    if current_user.id != @user.id
      raise('A user may not delete their own account')
    end

    @user.destroy!
    redirect_to users_path, notice: 'User was successfully deleted.'
  end

这里是我不断收到的错误消息摘录:

Routing Error
No route matches [DELETE] "/users"

new_user_path    GET     /users/new(.:format)    users#new
edit_user_path   GET     /users/:id/edit(.:format)   users#edit
user_path    PATCH   /users/:id(.:format)    users#update
PUT  /users/:id(.:format)    users#update
DELETE   /users/:id(.:format)    users#destroy

1 个答案:

答案 0 :(得分:0)

@davidrac和@apneadiving都在上面的评论中给出了正确的答案,这是因为@user应该是user