The *Agile Web Development with Rails* book has an explanation of sessions that I am having trouble following. Does anyone know of another good discussion of how Rails manages sessions. Specifically, in Firefox and and Internet Explorer ... is each browser window a session? Is each invocation of the browser a session? If I close a browser window ... can I restart the session? Exactly what is a session and how is state information maintained across browser requests? -- 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 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.
On Jan 3, 4:46 am, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> The *Agile Web Development with Rails* book has an explanation of > sessions that I am having trouble following. > > Does anyone know of another good discussion of how Rails manages > sessions. > > Specifically, in Firefox and and Internet Explorer ... is each browser > window a session? Is each invocation of the browser a session? > > If I close a browser window ... can I restart the session? > > Exactly what is a session and how is state information maintained across > browser requests?A session is tied to a cookie (depending on your session store that cookie either contains the session data or an identifier that allows rails to retrieve the session from memcache/database/disk etc.) Your questions above all boil down to what is the scope of a cookie and how long does it last. Cookies can have expiry dates set long in the future, but sessions are handled with cookies that are set to only last until the browser quits (not the same as just closing a window). Fred Fred> -- > Posted viahttp://www.ruby-forum.com/.-- 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.
Cookies can have expiry dates set long in the> future, but sessions are handled with cookies that are set to only > last until the browser quits (not the same as just closing a window).Let''s say that I''m using Firefox and I open multiple instances of Firefox ... so do all the instances of Firefox know about all the cookies? When, exactly, does a cookie with no expiration date disappear? Anyway, is there a more in-depth explanation available anywhere online that you can recommend? -- 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 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.
Hi Ralph, start here: http://guides.rubyonrails.org/action_controller_overview.html#session Regards, Nicolai -- 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.
On Jan 3, 12:35 pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Cookies can have expiry dates set long in the > > > future, but sessions are handled with cookies that are set to only > > last until the browser quits (not the same as just closing a window). > > Let''s say that I''m using Firefox and I open multiple instances of > Firefox ... so do all the instances of Firefox know about all the > cookies? >Try it! Fred> When, exactly, does a cookie with no expiration date disappear? > > Anyway, is there a more in-depth explanation available anywhere online > that you can recommend? > > -- > Posted viahttp://www.ruby-forum.com/.-- 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.
Hello, I have a little question. I want to an user edit or delete their comments. For it, I have this code: <% if post.usuario_id == session[:usuario_id] %> <td><%= link_to ''Editar'', {:action => ''edit'', :id => post.id} %></td> <% end %> You can see that post have a value "usuario_id" where the I must completed manually in the new post form. I want to change it and compare the name of the commenter: <% if post.nombre == session[:usuario_nombre] %> And my code of login: def login if request.post? usuario = Usuario.authenticate(params[:nombre], params[:password]) if usuario #Here, I changed usuario.id to usuario.nombre to store the name''s user in the session, right? #session[:usuario_nombre] = usuario.nombre session[:usuario_id] = usuario.id redirect_to(:action => "index") else flash.now[:notice] = "Usuario o contraseña no válido" end end end I thought that it could work, but not... I have modified the if sentence and the admin_controller and I see that it works for a moment! I logged out to try with other user and I received an error. I think that, when it works, I have this: <% if post.nombre == session[:usuario_nombre].nombre %> And I received this error, I think: "undefined method `nombre'' for 1:Fixnum" I''m surely that the problem is in the if sentence and/or admin_controller, in session[:param] = ... -- Posted via http://www.ruby-forum.com/. --0016e6407d7cdcbb46047d72404f Content-Type: text/plain; charset=ISO-8859-1 -- 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. --0016e6407d7cdcbb46047d72404f--
Hi Jorge, First of all, you mention that you have to give usuario_id manually every time you create a post. This doesn''t sound right at all to me. Do you create a post from the name of a user who is currently logged in? If so, you have his usuario_id in the session, don''t you? In the post#create action you create a new model instance from form parameters and set the post.usuario_id to session[:usuario_id]. Moreover, if you use one of the standard authentication plugins, you will have "current_user" available to almost any piece of the application (controllers, views, helpers), and so you can get your user ID from that. Your check then becomes: own_post = logged_in? && current_user.id == post.usuario_id To push it a bit further, you may want to move this piece into the application helper, like this: def owns?(resource) logged_in? && current_user.id == resource.usuario_id end And then your view becomes: <% if owns?(post) %> <td><%= link_to ''Editar'', {:action => ''edit'', :id => post.id} %></td> <% end %> I didn''t go far to the analysis of your error since the solution doesn''t sound right in the first place. Hope it helps. - Aleksey On Jan 19, 2:46 am, Jorge Fernandez <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello, I have a little question. > > I want to an user edit or delete their comments. For it, I have this > code: > > <% if post.usuario_id == session[:usuario_id] %> > <td><%= link_to ''Editar'', {:action => ''edit'', :id => post.id} > %></td> > <% end %> > > You can see that post have a value "usuario_id" where the I must > completed manually in the new post form. I want to change it and compare > the name of the commenter: > > <% if post.nombre == session[:usuario_nombre] %> > > And my code of login: > > def login > if request.post? > usuario = Usuario.authenticate(params[:nombre], > params[:password]) > if usuario > #Here, I changed usuario.id to usuario.nombre to store the name''s user > in the session, right? > #session[:usuario_nombre] = usuario.nombre > session[:usuario_id] = usuario.id > redirect_to(:action => "index") > else > flash.now[:notice] = "Usuario o contraseña no válido" > end > end > end > > I thought that it could work, but not... I have modified the if sentence > and the admin_controller and I see that it works for a moment! I logged > out to try with other user and I received an error. I think that, when > it works, I have this: > > <% if post.nombre == session[:usuario_nombre].nombre %> > > And I received this error, I think: > > "undefined method `nombre'' for 1:Fixnum" > > I''m surely that the problem is in the if sentence and/or > admin_controller, in session[:param] = ... > -- > Posted viahttp://www.ruby-forum.com/.-- 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.