我正在尝试让用户(未登录)在单击“您的个人资料”后被定向到登录页面
class ProfileController < ApplicationController
before_action :authenticate_user!
def user_profile
render(:template => "profile/my_profile.html.erb")
end
end
我尝试在我的控制器中为配置文件包含before_action :authenticate_user!
,但收到错误:undefined method 'authenticate_user!'
我有一个单独的控制器用于验证用户身份
1条答案
按热度按时间vbopmzt11#
你应该在
ProfileController
或者ApplicationController
中有一个authenticate_user!
方法,然后只有你才能像这样使用它。如果它在另一个控制器中,则可以复制它,或将它移动到模块关注点并附加到当前/应用程序控制器。