开发者

Is it okay to store the logged in user in the session in Ruby on Rails?

开发者 https://www.devze.com 2023-01-01 05:49 出处:网络
I\'m very new to RoR, and am trying to implement a user login system. I\'ve got most of it working, but I\'m trying to work out how I refer to the logged in user a开发者_StackOverflow中文版cross many

I'm very new to RoR, and am trying to implement a user login system. I've got most of it working, but I'm trying to work out how I refer to the logged in user a开发者_StackOverflow中文版cross many different views/controllers etc. Can I store the user in the session? Or is there a better way to do it?

Thanks for reading


You would more likely store the user id in the session, then get the actual user from somewhere else, like your datastore. That said, there are plugins to do authentication already, and you wouldn't need to worry about any of this if you used one.


Yes you can. Using something like Authlogic or Devise is preferred.


Since you're a newbie, do checkout Rails Tutorial - http://www.railstutorial.org/book. There's a chapter that covers login/logout/sign up stuffs.

0

精彩评论

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