Prabha Prabha - 6 months ago 15
SQL Question

count sql query used in rails 4

How to use count query in rails 4. I try to use , but I get

undefined method `where' for 57:Fixnum

my sample code is,

@empcount = Employee.count("emp_name")
.where("org_id = ? ", current_user.org_id)

What is the error with that?


Employee.count("emp_name") would return the total count of the employees.emp_name. A logical re-ordering of your query should return the result you're looking for:

@empcount = Employee.where("org_id = ? ", current_user.org_id).count("emp_name")