ciaodarwin.da-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2013-Jul-05 10:10 UTC
Ruby on Rails sessions
Hello I''m learning RoR and i would like to know more about the sessions in RoR Can anyone give me a good example for a session in a web application? or good pages for learning? (not: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book :P) Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6bb43892-ba43-4d4d-be73-075c04ac1839%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Did you already read Ruby on Rails Security Guide in Rails Guides ? http://guides.rubyonrails.org/security.html On Friday, July 5, 2013 6:10:28 AM UTC-4, ciaoda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Hello > > I''m learning RoR and i would like to know more about the sessions in RoR > > Can anyone give me a good example for a session in a web application? or > good pages for learning? > (not: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book :P) > > Thanks >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d5f93142-240a-4639-ad58-d8c6714da537%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
unknown wrote in post #1114514:> I''m learning RoR and i would like to know more about the sessions in RoR > > Can anyone give me a good example for a session in a web application? or > good pages for learning? > (not: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book :P)There''s really not a lot that you have to know about sessions in Rails. You can just think about them as a hash used to store small bits of information that you want to make available to all controller actions. For example if you want to remember the id of the logged in user, then in your action that authenticates you would store the user object''s id in the session hash: session[:user_id] = current_user.id By default Rails is configured to store session data in browser cookies. Every request included the session cookie. Rails will automatically read the cookie and create a Ruby Hash named session. Browser cookies are limited to 4K of data so it is good practice to keep session data as small as possible. Notice above we do not store the entire User object in the session, but only store the id of the user. Whenever you want the details about the user then you can lookup full user object by the stored id. There are several other option for storing session data. The data could be stored in the database using ActiveRecord. Or could be stored in a memcached, redis, or other NoSQL persistence service. Note that if you choose an alternative persistent store for your session data then it will be your responsibility to cleanup old sessions. Rails will not do that for you automatically. That''s one major advantage of storing sessions in cookies. It eliminates the need to manage old sessions. The only drawback I see is the 4K limit, but that should be plenty of space for the types of information you should keep in sessions. Also it''s worth noting that Rails 4 will begin encrypting the data in session cookies. Rails 3.2.x signs the cookies to prevent tampering, but does not encrypt the contents of the cookies. Just remember that any data stored in a session has to be loaded on EVERY request, regardless of whether the data is used by the action or not, so keep session data as small as possible. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9442d7c4eaf374f3f9418be60ed3aef0%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.