在Ruby on Rails中访问配置文件

hkmswyz6  于 2023-03-17  发布在  Ruby
关注(0)|答案(1)|浏览(189)

我正在尝试让用户(未登录)在单击“您的个人资料”后被定向到登录页面

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!'
我有一个单独的控制器用于验证用户身份

vbopmzt1

vbopmzt11#

你应该在ProfileController或者ApplicationController中有一个authenticate_user!方法,然后只有你才能像这样使用它。
如果它在另一个控制器中,则可以复制它,或将它移动到模块关注点并附加到当前/应用程序控制器。

相关问题