Robot.count is actually the solution you want.
Looking at one of the comments above, it looks like you may have a misunderstanding of how .count works. It returns the number of all rows in the table only if there are no parameters.
but if you go into the same conditions that you go to all / find, for example:
Robot.count(:conditions => {:a => 'b'})
.count () will return the number of lines matching the specified conditions. To be obvious - you can even save the hash condition as a variable, to go both ways - reduce duplication, therefore:
conds = {:a => 'b'} @robots = Robot.all(:conditions => conds, :limit => 50) @num_robots = Robot.count(:conditions => conds)
This means that you cannot make an account after the fact in the result set (as in your example). those. you cannot just run your query and then ask how many rows would be found. You really need to call .count specifically.
source share