我正在寻找解决方案。当他们不是管理员时,我正在尝试重定向用户。
我做到了:
def is_admin?
if current_user.admin?
redirect_to action: "index"
else
redirect_to root_path
end
end
我在before_action :is_admin?
有posts_controller
我不知道为什么,但重定向不起作用。 Firefox给了我一个空白页面:
页面未正确重定向
谢谢你的帮助
问题是你的before_action :is_admin?
在索引方法上调用is_admin?
并继续重定向...
我不明白为什么重定向'索引',你应该改变你的方法is_admin?
像:
def is_admin?
# redirect ONLY if user isn't admin
redirect_to root_path unless current_user.admin?
end