I have the following action that is supposed to test whether a username
exists or not. It seems that the first condition never fails. I have put
nothing in the params[:l] hash and the first condition executes. Any
ideas?
def index
@oLogin = User.find_by_login(params[:l])
if @oLogin.login != nil
@sLoggedInName = @oLogin.login + ", you''ve logged in
successfully"
else
render :controller => ''session''
end
end
--
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
-~----------~----~----~----~------~----~------~--~---
I think it is @oLogin that you need to test for nil before accessing @oLogin.login. This is to check whether the find returned anything. 2009/3/10 Chris Gunnels <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > I have the following action that is supposed to test whether a username > exists or not. It seems that the first condition never fails. I have put > nothing in the params[:l] hash and the first condition executes. Any > ideas? > > def index > @oLogin = User.find_by_login(params[:l]) > if @oLogin.login != nil > @sLoggedInName = @oLogin.login + ", you''ve logged in successfully" > else > render :controller => ''session'' > end > end > -- > 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 -~----------~----~----~----~------~----~------~--~---
Chris Gunnels wrote:> I have the following action that is supposed to test whether a username > exists or not. It seems that the first condition never fails. I have put > nothing in the params[:l] hash and the first condition executes. Any > ideas? > > def index > @oLogin = User.find_by_login(params[:l]) > if @oLogin.login != nilif @oLogin You ought to read some Rails tutorials and projects for a while; these patterns must soak in! Also, nobody around here uses HN like oLogin. We know it''s an ''o''bject already! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Colin Law wrote:> I think it is @oLogin that you need to test for nil before accessing > @oLogin.login. This is to check whether the find returned anything. > > 2009/3/10 Chris Gunnels <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thx...> Also, nobody around here uses HN like oLogin. We know it''s an ''o''bject > already!good point...I come from a PHP background so not everything is an object, I just have to get used to that. -- 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 -~----------~----~----~----~------~----~------~--~---
>> Also, nobody around here uses HN like oLogin. We know it''s an ''o''bject >> already! > > good point...I come from a PHP background so not everything is an > object, I just have to get used to that.Ruby offers very flexible syntax, with many different alternatives for each statement, so we generally try to select the sequence that... ...most closely resembles English... ...or whatever your favorite human language is. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---