Topic: record count sintaxe

Hi all, I´m newbie in Rails so I have 2 entities:
products and assets !
products has_many assets
assets belongs_to products
so in my view i´d like to show assets records count for each products, so the line is:
<% for product in @products %>
<div class="products">
    <h2><%= link_to product.title, product_path(product) %></h2>
    <p>
        <%= product.content %>
    </p>
    <p>
        Total of Imagens =  <%= @assets.count %>
    </p>
</div>
<% end %>

rails returns:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.count

how to do that ?
thanks in advance

Last edited by PowerTux (2013-03-19 19:34:12)

Re: record count sintaxe

A big chunk of your code appears to be missing. Please edit your post so we can read and hopefully help you out.

Re: record count sintaxe

Hi Danabrit, i fixed it, thanks smile

danabrit wrote:

A big chunk of your code appears to be missing. Please edit your post so we can read and hopefully help you out.

Re: record count sintaxe

ooops, i did it:

<%= product.assets.count %>

so easy, it runs now, thanks smile

Re: record count sintaxe

Glad I could help. ;-)