Tuesday, May 12, 2009

Count returned result Ruby On Rails

In order to display the number of items of a type, use the count method.

I have two classes Type and Entities. An entity has a type. If I want to count how many entities have the same type I would do


(<%= Entity.count(:conditions =>{:Type_id => type.id})%>)
or


(<%= Entity.count(:conditions =>{:Type_id => type.1})%>)

Which would return something like

Number of entities (26)

No comments:

Post a Comment