Logging out feature, Code: def logout @title = "Login - Books" session[:user_id] != nil flash[:notice] = "You have sucessfully been logged out !" redirect_to :controller => :books, :action => :index end end ^^when this is run, it logs the user out (nill) and displays you have successfully been logged out, Code v2: def logout @title = "Login - Books" session[:user_id] != nil flash[:notice] = "You have sucessfully been logged out #{@user.screen_name} !" redirect_to :controller => :books, :action => :index end end ^^what i was hoping this would do is to display the users name as well, (this is another task), i understand the session but how can i bring the session back while the session is nill :S thanks once again mates, Jagmit Gabba -- 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.
Quoting Jagmit Gabba <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Logging out feature, > > Code: > > def logout > @title = "Login - Books" > > session[:user_id] != nil > flash[:notice] = "You have sucessfully been logged out !" > redirect_to :controller => :books, :action => :index > end > end > > ^^when this is run, it logs the user out (nill) and displays you have > successfully been logged out, > > Code v2: > def logout > @title = "Login - Books" > > session[:user_id] != nil > flash[:notice] = "You have sucessfully been logged out > #{@user.screen_name} !" > redirect_to :controller => :books, :action => :index > end > end > > ^^what i was hoping this would do is to display the users name as well, > (this is another task), i understand the session but how can i bring the > session back while the session is nill :S >Where is the instance variable @user set? If it were my code, I''d do something like this: def logout @title = "Login - Books" name = User.find(session[:user_id]) session[:user_id] != nil flash[:notice] = "You have sucessfully been logged out #{name}!" redirect_to :controller => :books, :action => :index end HTH, Jeffrey -- 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.
Jeffrey L. Taylor wrote:> Quoting Jagmit Gabba <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: >> end >> flash[:notice] = "You have sucessfully been logged out >> #{@user.screen_name} !" >> redirect_to :controller => :books, :action => :index >> end >> end >> >> ^^what i was hoping this would do is to display the users name as well, >> (this is another task), i understand the session but how can i bring the >> session back while the session is nill :S >> > > Where is the instance variable @user set? If it were my code, I''d do > something like this: > > def logout > @title = "Login - Books" > > name = User.find(session[:user_id]) > session[:user_id] != nil > flash[:notice] = "You have sucessfully been logged out #{name}!" > redirect_to :controller => :books, :action => :index > end > > HTH, > JeffreyGood afternoon friend, Your code doesnt seem to be working as it gives me a SyntaxError, at the end i added another end cause of the nill, it seems to work but the only thing which is displayed is "You have successfully been logged out #!" just that, no username. -- 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.
Quoting Jagmit Gabba <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Jeffrey L. Taylor wrote: > > Quoting Jagmit Gabba <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: > >> end > >> flash[:notice] = "You have sucessfully been logged out > >> #{@user.screen_name} !" > >> redirect_to :controller => :books, :action => :index > >> end > >> end > >> > >> ^^what i was hoping this would do is to display the users name as well, > >> (this is another task), i understand the session but how can i bring the > >> session back while the session is nill :S > >> > > > > Where is the instance variable @user set? If it were my code, I''d do > > something like this: > > > > def logout > > @title = "Login - Books" > > > > name = User.find(session[:user_id]) > > session[:user_id] != nil > > flash[:notice] = "You have sucessfully been logged out #{name}!" > > redirect_to :controller => :books, :action => :index > > end > > > > HTH, > > Jeffrey > > Good afternoon friend, > > Your code doesnt seem to be working as it gives me a SyntaxError, at the > end i added another end cause of the nill, it seems to work but the only > thing which is displayed is "You have successfully been logged out #!" > just that, no username.Oops, change: name = User.find(session[:user_id]) To: name = User.find(session[:user_id], :select => ''screen_name'').screen_name Or maybe clearer: def logout @title = "Login - Books" user = User.find(session[:user_id], :select => ''screen_name'') session[:user_id] != nil flash[:notice] = "You have sucessfully been logged out #{user.screen_name}!" redirect_to :controller => :books, :action => :index end And yes, you need the additional end to close the class. Jeffrey -- 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 21 March 2010 15:59, Jagmit Gabba <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Logging out feature, > > Code: > > def logout > @title = "Login - Books" > > session[:user_id] != nilDo you mean session[:user_id] = nil Colin> flash[:notice] = "You have sucessfully been logged out !" > redirect_to :controller => :books, :action => :index > end > end > > ^^when this is run, it logs the user out (nill) and displays you have > successfully been logged out, > > Code v2: > def logout > @title = "Login - Books" > > session[:user_id] != nil > flash[:notice] = "You have sucessfully been logged out > #{@user.screen_name} !" > redirect_to :controller => :books, :action => :index > end > end > > ^^what i was hoping this would do is to display the users name as well, > (this is another task), i understand the session but how can i bring the > session back while the session is nill :S > > thanks once again mates, > > Jagmit Gabba > -- > 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@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.
Thank you very much Jeffrey and Colin... :) It worked perfectly and change the != to -- 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.