Alina
Alina

Reputation: 2261

RoR: retrieve values from database and show in view

I was trying to count my objects and to show the number in view by doing something like this:

show.html.erb:

 <%Files.where(defined:"yes").count do |number|%>
    <%= number %>
    <% end %>

But it shows nothing. Where is the problem? Thanks a lot.

Upvotes: 0

Views: 36

Answers (1)

Dylan Markow
Dylan Markow

Reputation: 124479

.count returns an integer value, not an array, so you can't iterate over it. Just do this:

<%= Files.where(defined: "yes").count %>

Upvotes: 4

Related Questions