NoMethodError [depot]

Hi

I’m a newbie here and to RoR, so forgive me if this is an over simple
question.

I’m running through the PragProg Agile Web D. with Ruby on
Rails, and I’ve got stuck on the Depot application.

When trying to view the ‘store’ I get this error:
NoMethodError in Store#index.rhtml


Showing app/views/store/index.rhtml where line #3 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 #3):

1:


2: <%
3: for product in @products
4: %>
5:
6:

I’m Running:
Ruby version 1.8.4 (i486-linux) [Ubuntu]
RubyGems version 0.9.0
Rails version 1.1.4
Environment development
Database adapter mysql

I’ve retraced all the steps given in the book - but can’t resolve the
problem - what are the likely causes of this to be? Is this most
likely to be the call to the database?

Thanks
Angela

Hi Angela,

if you didn’t mistype anything in product.rb and store_controller.rb,
I’d say there’s a problem with the db. Look in
depot/log/development.log for any errors and check the db whether the
required tables exists and are populated.

Best regards,

Eric

On 9/1/06, ange [email protected] wrote:

When trying to view the ‘store’ I get this error:

RubyGems version 0.9.0
Rails version 1.1.4
Environment development
Database adapter mysql

I’ve retraced all the steps given in the book - but can’t resolve the
problem - what are the likely causes of this to be? Is this most
likely to be the call to the database?

Thanks
Angela

Line 3 calls for @products which is nil at the time in the index view,
meaning that there are no products in your variable. Do you have
something
that populates the instance variable @products in your
StoreController#index
method?

On 9/1/06, ange [email protected] wrote:

Thanks!
A

ange,

Glad you found it.

With some discussion about recently about depricated usages, with
warnings
and such available in plugins etc, the usage of @content_for_layour is
depricated.

Instead you should use

<%= yield %> or <%= yeild :layout %>

thanks both for this

this problem was actually caused by:
<%=@content_for_layout%>

being missing from store.rhtm

it’s all working just fine now - i just have much less hair!

Thanks!
A