0

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
4

1 回答 1

0

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

于 2013-08-15T13:43:38.427 回答