Forum: Ruby on Rails Help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
cory m. (Guest)
on 2007-01-28 22:08
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:     <th><%= column.human_name %></th>
7:   <% end %>
8:   </tr>
9: <% for account in @accounts %>
10:   <tr>
11:   <% for column in Account.content_columns %>
12:     <td><%=h account.send(column.name) %></td>

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.
Dave C. (Guest)
on 2007-01-29 01:17
> 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%>
cory m. (Guest)
on 2007-01-31 01:07
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.
This topic is locked and can not be replied to.