Rails - Finding the count of user's who have created posts

1k views Asked by At

I wish I could give you guys some code but this question is more of a math problem and doesn't need code to solve.

I'm trying to find a number. The number shows the total count of users who have created Posts. Say my app has 25 posts and those posts come from 4 different users, then the count equals 4. How can I get this count??

The count is for this

@collections = Collection.all

Finding the number of users who have created a Collection.

Thanks so much.

1

There are 1 answers

0
fivedigit On

You can do this:

Collection.distinct.count(:user_id)

This will execute a count query and only return the number of unique users who created a Collection.