# Help

**URL:** <https://www.ruby-forum.com/t/help/83685>\
**Category:** Rails\
**Created:** [January 28, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/help/83685 "2007-01-28T21:08:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![clawson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@clawson](https://www.ruby-forum.com/u/clawson)\
**Post date:** [January 28, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/help/83685/1 "2007-01-28T21:08:57Z")

</div>

I am working on a web app that attaches to a MySQL database.

I can add users through the admin\_controller just fine without  
“before\_filter :authorize”

I need that statement obviously. When I try to login with my admin  
password I get this

NoMethodError in Login#index

Showing app/views/login/index.rhtml where line #9 raised:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.each

Extracted source (around line #9):

6:

\<%= column.human\_name %\>  
7: \<% end %\>  
8:   
9: \<% for account in @accounts %\>  
10:   
11: \<% for column in Account.content\_columns %\>  
12: \<%=h account.send(column.name) %\>

RAILS\_ROOT: ./script/…/config/…  
Application Trace | Framework Trace | Full Trace

#{RAILS\_ROOT}/app/views/login/index.rhtml:9:in `_run_rhtml_login_index' -e:4:in`load’  
-e:4

Any suggestions would be appreciated.

---

<div class="post-metadata">

**Author:** ![clawson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@clawson](https://www.ruby-forum.com/u/clawson)\
**Post date:** [January 29, 2007, 12:17am UTC](https://www.ruby-forum.com/t/help/83685/2 "2007-01-29T00:17:03Z")

</div>

> Any suggestions would be appreciated.

Either there are no @accounts being returned or haven’t setup the  
@accounts instance variable in your controller.

Try putting a condition before the loop that checks to see if there are  
any accounts in @accounts like:

\<%if @accounts.nil?%\>  
no accounts or account instance var  
\<%else%\>  
I have this many accounts: \<%=@accounts.length%\>  
#your stuff here  
\<%end%\>

---

<div class="post-metadata">

**Author:** ![clawson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@clawson](https://www.ruby-forum.com/u/clawson)\
**Post date:** [January 31, 2007, 12:07am UTC](https://www.ruby-forum.com/t/help/83685/3 "2007-01-31T00:07:56Z")

</div>

David C. wrote:

> > Any suggestions would be appreciated.
> 
> Either there are no @accounts being returned or haven’t setup the  
> @accounts instance variable in your controller.
> 
> Try putting a condition before the loop that checks to see if there are  
> any accounts in @accounts like:
> 
> \<%if @accounts.nil?%\>  
> no accounts or account instance var  
> \<%else%\>  
> I have this many accounts: \<%=@accounts.length%\>  
> #your stuff here  
> \<%end%\>

Thanks a lot David! I was able to get this going. Thank you.
