开发者

Rails & Paperclip: Variable File Size Limit

开发者 https://www.devze.com 2023-02-12 07:07 出处:网络
I currently have a Rails app in which users of different ranks can upload files (via Paperclip). I know I can set a global file size limit in the model, however I\'m looking to enforce different file

I currently have a Rails app in which users of different ranks can upload files (via Paperclip). I know I can set a global file size limit in the model, however I'm looking to enforce different file size limits depending on the users' rank.

Does anyone know how I can accomplis开发者_运维问答h this?


The easiest answer is that you write activerecord validations. e.g. write following at model:

validate :some_name

def some_name
  errors_add(:file_file_size, 'error message') if file_file_size > 2.megabytes && user.rank > ...
end
0

精彩评论

暂无评论...
验证码 换一张
取 消