0
現在只有current_user
可以編輯自己的帳號,但只有admin
可以刪除帳號。不知道如何授予管理員編輯用戶權限,因爲current_user
函數正在阻止它。rails before_action困境
users_controller.rb
class UsersController < ApplicationController
before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update]
before_action :admin_user, only: [:index, :destroy]
...
private
...
# Confirms the correct user.
def correct_user
@user = User.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
# Confirms an admin user.
def admin_user
redirect_to(root_url) unless current_user.admin?
end
end
不知道爲什麼,但仍然指揮我的根URL,當我嘗試編輯 – DanielsV
我的錯誤:(從current_user.admin刪除!? –