我是新來的這兩個網站和Rails,我發現這是一個常見的用法把這樣的事情在控制器的開頭:爲什麼使用before_action可以安全使用:authenticate_admin?
before_action :authenticate_admin, only: [:only_admin]
其中
def authenticate_admin
unless current_user.admin?
flash[:alert] = "You are not admin!"
redirect_to '/'
end
end
考慮,如果它是可能以某種方式忽略來自客戶端的重定向,我感覺真的不安全。 redirect_to
如何實施?爲什麼這個用法能保證安全?