0

I've been reading this post. Validate image size in carrierwave uploader

It looks like my validator is working correctly, but, I don't get the alert notice. I just get redirected to the form again.

How can I add a rails alert notice to this? Thanks !

def validate_minimum_image_size
  image = MiniMagick::Image.open(photo.path)
  unless image[:width] > 400 && image[:height] > 400
  errors.add :image, alert: "should be 400x400px minimum!" 
end

Photos controller create method:

def create
    @photo = Photo.new(photo_params)
    @photo.user = current_user

    if @photo.save
        redirect_to [current_user, @photo], notice: 'El spot se ha subido correctamente!'
    else
        puts 'shit!!!!!!'
        render 'new'
    end
end
Community
  • 1
  • 1
Gibson
  • 2,055
  • 2
  • 23
  • 48

1 Answers1

0

Ok fixed, I changed

errors.add :image, alert: "should be 400x400px minimum!"

to

errors.add :photo, alert: "should be 400x400px minimum!"

Gibson
  • 2,055
  • 2
  • 23
  • 48