Setting upload limits

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

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.