0

I am working on a rails project, using Carrierwave for uploading files and images. I just need a way to count number of files uploaded to server via carrierwave. Something like AvatarUploader.all.count ?

Thanks.

2
  • maybe counter_cache will help you? Jan 23, 2016 at 23:38
  • @DavidKristianLaundav Nothing at all, I guess there must be a ruby based solution to this, like counting all the uploader directory images/files recursively! Jan 23, 2016 at 23:59

1 Answer 1

0

If there is a Model A, make a has_many association to Model A_attachments that gets created for each attachment and simply count them by A_attachments.count.

For counting the number of models in record, you just need ModelName.count and that's it.

There's a really detailed explanation from a user named SSR in this link https://stackoverflow.com/a/21412174

I don't want to copy and paste the answer because he really deserves an upvote for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.