Filippos
2011-Feb-05 18:09 UTC
Questions about Chapter 9: Sign in, Sign out of RoR Tutorial | Learn Rails by Example
Hello Finished reading chapter 9 and im a little bit confused. 1. In the tutorial, Modules are used instead of creating a Model and working in a class inside a module , like in authenticating passwords. Wouldn''t that be possible? Or is it unnecessary since we''re not messing with a database in terms of storing data? 2. what is the difference between session[:remember_token] = user.id and cookies[:remember_token] ? Session stores the cookie locally until we exit the browser and then it gets deleted whereas cookies is permanent stored even after we exit the browser? 3. In section 9.3.3 we are being introduced to the curent user with the code in the module SessionsHelper self.current_user = user Why do we use the "self"? and not just current_user since we use it as a variable object and not as an object attribute ? Or is it a way to say sessions.current_user = user ? 4. What''s the purpose of def current_user=(user) and of def current_user in listing 9.16 ? Couldnt we avoid all that using a single method? Thank you in advance! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Feb-05 19:51 UTC
Re: Questions about Chapter 9: Sign in, Sign out of RoR Tutorial | Learn Rails by Example
On 5 Feb 2011, at 18:09, Filippos <filipposkip-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello > > Finished reading chapter 9 and im a little bit confused. >Not familiar with that particular tutorial but ...> 1. In the tutorial, Modules are used instead of creating a Model and > working in a class inside a module , like in authenticating passwords. > Wouldn''t that be possible? Or is it unnecessary since we''re not > messing with a database in terms of storing data?Not sure what you are getting at there.> > 2. what is the difference between session[:remember_token] = user.id > and cookies[:remember_token] ? > Session stores the cookie locally until we exit the browser and then > it gets deleted whereas cookies is permanent stored even after we exit > the browser?Sessions are stored using cookies (either in the cookie itself or by having a cookie that points at something in the database or memcache). The cookie supporting a session is set to expire when the browser quits whereas ''normal'' cookies need not be. Also, rails handles serialising arbitrary ruby objects into the session, I don''t think it will do that for cookie values.> > 3. In section 9.3.3 we are being introduced to the curent user with > the code in the module SessionsHelper > self.current_user = user > > Why do we use the "self"? and not just current_user since we use it as > a variable object and not as an object attribute ? Or is it a way to > say sessions.current_user = user ? >If you didn''t then it would just be creating a local variable called current_user, rather than calling the current_user= method> 4. What''s the purpose of def current_user=(user) and of def > current_user in listing 9.16 ? Couldnt we avoid all that using a > single method?One''s the setter method, the other is the getter. Doesn''t seem like much point is combining the two. Fred> > Thank you in advance! > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Filippos
2011-Feb-05 21:22 UTC
Re: Questions about Chapter 9: Sign in, Sign out of RoR Tutorial | Learn Rails by Example
Its the tutorial http://railstutorial.org/ On Feb 5, 9:51 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5 Feb 2011, at 18:09, Filippos <filippos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello > > > Finished reading chapter 9 and im a little bit confused. > > Not familiar with that particular tutorial but ... > > > 1. In the tutorial, Modules are used instead of creating a Model and > > working in a class inside a module , like in authenticating passwords. > > Wouldn''t that be possible? Or is it unnecessary since we''re not > > messing with a database in terms of storing data? > > Not sure what you are getting at there. > > > > > 2. what is the difference between session[:remember_token] = user.id > > and cookies[:remember_token] ? > > Session stores the cookie locally until we exit the browser and then > > it gets deleted whereas cookies is permanent stored even after we exit > > the browser? > > Sessions are stored using cookies (either in the cookie itself or by having a cookie that points at something in the database or memcache). The cookie supporting a session is set to expire when the browser quits whereas ''normal'' cookies need not be. Also, rails handles serialising arbitrary ruby objects into the session, I don''t think it will do that for cookie values. > > > 3. In section 9.3.3 we are being introduced to the curent user with > > the code in the module SessionsHelper > > self.current_user = user > > > Why do we use the "self"? and not just current_user since we use it as > > a variable object and not as an object attribute ? Or is it a way to > > say sessions.current_user = user ? > > If you didn''t then it would just be creating a local variable called current_user, rather than calling the current_user= method > > > 4. What''s the purpose of def current_user=(user) and of def > > current_user in listing 9.16 ? Couldnt we avoid all that using a > > single method? > > One''s the setter method, the other is the getter. Doesn''t seem like much point is combining the two. > > Fred > > > > > Thank you in advance! > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Feb-05 21:27 UTC
Re: Questions about Chapter 9: Sign in, Sign out of RoR Tutorial | Learn Rails by Example
On 5 February 2011 18:09, Filippos <filipposkip-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello > > Finished reading chapter 9 and im a little bit confused. > > 1. In the tutorial, Modules are used instead of creating a Model and > working in a class inside a module , like in authenticating passwords. > Wouldn''t that be possible? Or is it unnecessary since we''re not > messing with a database in terms of storing data?Classes that do not have database storage can be in modules or models, if that is the question you are asking. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Filippos
2011-Feb-06 12:57 UTC
Re: Questions about Chapter 9: Sign in, Sign out of RoR Tutorial | Learn Rails by Example
right, ok , that makes sense. But in this chapter i see that the author is avoiding using a model. Is this a common practice in rails or just a personal choice of the author? What if we want to list the users who are currently logged in our website ? That would require a model with access to the database right? So a module wouldnt be of any use since the data would be lost? Session Model with CRUD and REST if we want to include a link for our users to check out other registered users who are browsing the website... ? On Feb 5, 11:27 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 5 February 2011 18:09, Filippos <filippos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello > > > Finished reading chapter 9 and im a little bit confused. > > > 1. In the tutorial, Modules are used instead of creating a Model and > > working in a class inside a module , like in authenticating passwords. > > Wouldn''t that be possible? Or is it unnecessary since we''re not > > messing with a database in terms of storing data? > > Classes that do not have database storage can be in modules or models, > if that is the question you are asking. > > Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.