开发者

How can I create a default "Guest" session so that the Devise helper current_user will show my Guest user?

I want all users开发者_Go百科 to my site to have a default "Guest" session. I am using Devise. All of my devise code is working for signed up users, but I also have a user record for a "Guest" user.

All I want to do is automatically log someone in as that user, so that in my views and elsewhere, the call to Devise's current_user will not fail.

I have spent since the end of September trying to find an answer for this. I can't even get a reply on the Devise mailing list.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜