# Setting upload limits

**URL:** <https://www.ruby-forum.com/t/setting-upload-limits/110018>\
**Category:** Rails\
**Created:** [July 21, 2007, 9:21am UTC](https://www.ruby-forum.com/t/setting-upload-limits/110018 "2007-07-21T09:21:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcgrigsby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5e925/32.png) [@dcgrigsby](https://www.ruby-forum.com/u/dcgrigsby)\
**Post date:** [July 21, 2007, 9:21am UTC](https://www.ruby-forum.com/t/setting-upload-limits/110018/1 "2007-07-21T09:21:26Z")

</div>

Hi, I was wondering what would be the best way to limit the number of  
file uploads per user using attachment\_fu and a :has\_many relationship.

-Thanks

---

<div class="post-metadata">

**Author:** ![dcgrigsby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5e925/32.png) [@dcgrigsby](https://www.ruby-forum.com/u/dcgrigsby)\
**Post date:** [July 26, 2007, 12:45am UTC](https://www.ruby-forum.com/t/setting-upload-limits/110018/2 "2007-07-26T00:45:43Z")

</div>

On 21 Jul 2007, at 08:21, Dan G. wrote:

> Hi, I was wondering what would be the best way to limit the number of  
> file uploads per user using attachment\_fu and a :has\_many  
> relationship.

You could check your threshold in a before\_create callback.

E.g. with models User and Upload (this is untested, off the top of my  
head):

class Upload \< ActiveRecord::Base  
belongs\_to :user  
has\_attachment etc.

def before\_create  
raise “Please no more - the horror!” unless user.uploads.count \< 5  
end  
end

Regards,  
Andy S.
