Forum: Ruby on Rails please help me......

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.
Prashant T. (Guest)
on 2006-04-05 14:08
Hi...

I have list.rhtml file default generated by scaffold for user table.
This file displays list of all user table rows. Inside this file I want
to display the list of the all the rows from my anothe table (stores).
How to do that?
I tried with following inside my above list.rhtml.
==================
 <% for store in @stores %>
  <tr>
  <% for column in Store.content_columns %>
    <td><%=h store.send(column.name) %></td>
  <% end %>
    <td></td>
  </tr>
<% end %>
==================

But its giving me error like:-

===============
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
===============

I think I am getting above error because list.rhtml file is in user view
& not in store view . How to fix above error ?
Alan F. (Guest)
on 2006-04-05 14:13
Prashant T. wrote:
> Hi...
>
> I have list.rhtml file default generated by scaffold for user table.
> This file displays list of all user table rows. Inside this file I want
> to display the list of the all the rows from my anothe table (stores).
> How to do that?

You need to populate the @stores variable before using it.  If you look
in UserController#list you'll see how @users is populated.

If you go to the UserController#list method, add

   @stores = Store.find(:all)

Variables are created in the controller and then accessed in the view.

Alan
This topic is locked and can not be replied to.