Hi, Its like every time I try to do something I get a error, and every time I search on the Internet I find things more complicated? The thing I''m doing is very simple. @user = User.find(:first, :conditions => ["username = ?", params[:user][:username]] ) if @user.username? redirect_to :action => ''account'' end This should be simple login system, I want to check if the username exists in the table? But this give me NIL exception? //Jamal -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> @user = User.find(:first, :conditions => ["username = ?", > params[:user][:username]] ) > if @user.username? > redirect_to :action => ''account'' > end > > This should be simple login system, I want to check if the username > exists in the table? But this give me NIL exception?Suppose username you are looking for does not exist. User.find will return nil. Next you call username on nil... oops. Try @user instead of @user.username Regards, Rimantas -- http://rimantas.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rimantas Liubertas wrote:>> @user = User.find(:first, :conditions => ["username = ?", >> params[:user][:username]] ) >> if @user.username? >> redirect_to :action => ''account'' >> end >> >> This should be simple login system, I want to check if the username >> exists in the table? But this give me NIL exception? > > Suppose username you are looking for does not exist. > User.find will return nil. Next you call username on nil... oops. > > Try @user instead of @user.username > > Regards, > Rimantas > -- > http://rimantas.com/Thats works perfect, but could I do this? if @user.username != nil -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Feb-17 12:30 UTC
Re: every step error? why that?
Hi -- On Sat, 17 Feb 2007, Jamal Soueidan wrote:> > Rimantas Liubertas wrote: >>> @user = User.find(:first, :conditions => ["username = ?", >>> params[:user][:username]] ) >>> if @user.username? >>> redirect_to :action => ''account'' >>> end >>> >>> This should be simple login system, I want to check if the username >>> exists in the table? But this give me NIL exception? >> >> Suppose username you are looking for does not exist. >> User.find will return nil. Next you call username on nil... oops. >> >> Try @user instead of @user.username >> >> Regards, >> Rimantas >> -- >> http://rimantas.com/ > > Thats works perfect, but could I do this? > > if @user.username != nilNo, because the problem is that @user itself might be nil. If it is, you don''t want to call username on it at all. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
unknown wrote:> Hi -- > > On Sat, 17 Feb 2007, Jamal Soueidan wrote: > >>> >> Thats works perfect, but could I do this? >> >> if @user.username != nil > > No, because the problem is that @user itself might be nil. If it is, > you don''t want to call username on it at all. > > > David > > -- > Q. What is THE Ruby book for Rails developers? > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) > (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) > Q. Where can I get Ruby/Rails on-site training, consulting, coaching? > A. Ruby Power and Light, LLC (http://www.rubypal.com)True :) Thanks for your help :D -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---