# Every step error? why that?

**URL:** <https://www.ruby-forum.com/t/every-step-error-why-that/85900>\
**Category:** Rails\
**Created:** [February 17, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/every-step-error-why-that/85900 "2007-02-17T13:06:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [February 17, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/every-step-error-why-that/85900/1 "2007-02-17T13:06:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [February 17, 2007, 1:13pm UTC](https://www.ruby-forum.com/t/every-step-error-why-that/85900/2 "2007-02-17T13:13:22Z")

</div>

> ```
> @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/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [February 17, 2007, 1:28pm UTC](https://www.ruby-forum.com/t/every-step-error-why-that/85900/3 "2007-02-17T13:28:05Z")

</div>

Rimantas L. 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/](http://rimantas.com/)

Thats works perfect, but could I do this?

if @user.username != nil

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [February 17, 2007, 1:31pm UTC](https://www.ruby-forum.com/t/every-step-error-why-that/85900/4 "2007-02-17T13:31:24Z")

</div>

Hi –

On Sat, 17 Feb 2007, Jamal S. 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](http://www.manning.com/black))  
(See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](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](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [February 17, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/every-step-error-why-that/85900/5 "2007-02-17T14:54:14Z")

</div>

unknown wrote:

> Hi –
> 
> On Sat, 17 Feb 2007, Jamal S. 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](http://www.manning.com/black))  
> (See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](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](http://www.rubypal.com))

True 🙂

Thanks for your help 😃
