4

我希望我网站的所有用户都有一个默认的“访客”会话。我正在使用设计。我所有的设计代码都适用于注册用户,但我也有一个“访客”用户的用户记录。

我要做的就是自动以该用户身份登录某人,这样在我的视图和其他地方,对 Devise 的 current_user 的调用不会失败。

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

4

1 回答 1

3
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
于 2010-11-12T21:40:42.367 回答