我希望我网站的所有用户都拥有默认的“访客”会话。我正在使用Devise。我的所有设计代码都适用于已注册的用户,但我也有“访客”用户的用户记录。
我想要做的就是自动将某人作为该用户登录,以便在我的视图和其他地方,对Devise的current_user的调用不会失败。
我自9月底以来一直试图找到答案。我甚至无法在Devise邮件列表上得到回复。
答案 0 :(得分: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