嘿,我正在试图摧毁一个用设计创建的用户。
以下是我的文件:
users_controller.rb
before_action :find_user
def destroy
@user.destroy
if @user.destroy
redirect_to admin_users_path, notice: "User destroyed"
end
end
routes.rb
devise_for :users
match 'users/:id' => 'users#destroy', :via => :delete, :as => :admin_destroy_user
视图:
= link_to "delete", admin_destroy_user_path(u), method: :delete, data: {confirm: "You sure?"}
但是我收到以下错误消息:
NameError in UsersController#destroy
uninitialized constant User::Profile
答案 0 :(得分:0)
试试这个:
before_action :find_user
def destroy
if @user.destroy # in this place you will destroy your user
redirect_to admin_users_path, notice: "User destroyed"
end
end