Rob Hughes
Rob Hughes

Reputation: 906

Rails. Count records that have a specific attribute:string

I have a model with a string attribute. This attribute (status) is updated to seen, notseen, hired, and reject depending on certain variables within my app.

I would like to count all records where status != reject.

Looking at the docs here it looks like it should be something like;

<%= Mymodel.count(:conditions => [ "status = ?", 'reject' ]) %>

but this is not correct, it returns a count of all instances regardless of status.

How can I achieve this?

Upvotes: 0

Views: 585

Answers (2)

Chakreshwar Sharma
Chakreshwar Sharma

Reputation: 2610

Try the below

<%= MyModel.where.not(:status =>  'reject').count %>

Upvotes: 1

Marco Roth
Marco Roth

Reputation: 184

Maybe something like this:

<%= MyModel.where.not(status: 'reject').count %>

Upvotes: 1

Related Questions