ruby on rails - How to prevent user to upload a big file with ActiveAdmin? -


i'm using activeadmin. in 1 of views user can upload picture, want show error if trying upload file bigger x size. how can that? code far:

form(html: { multipart: true }) |f|  f.inputs "bs"    f.input :latitude, as: :hidden    f.input :longitude, as: :hidden    f.input :name    f.input :picture, as: :file  end    f.actions end 

your going have write custom validation in model, if using paperclip doesn't allow pass function limits size.

the validation this

validate :validate_image_size  def validate_image_size   if document.file? && document.size > get_current_file_size_limit     errors.add_to_base(" ... error message")   end end    private  def get_current_file_size_limit   10.megabytes # dynamically change end 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -