我希望所有用户访问我的网站默认“访客”会话。我正在使用设计。我所有的设计代码都为注册用户工作,但是我也有“访客”用户的用户记录。

我要做的就是自动将某人作为该用户登录,以便在我的视图和其他地方,呼吁设计的Current_user不会失败。

自9月底以来,我一直在尝试找到答案。我什至无法在设计邮件列表上得到答复。

有帮助吗?

解决方案

def set_user
  if current_user.blank?
    user = User.where(:email => "guest@mycompany").first
    if user.blank?
      redirect_to new_user_registration_path
    else
      sign_in(user) # Why was this so hard to find out? I had to read all of the Devise code.
    end
  end
end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top