vendredi 14 août 2015

Paperclip plugin restrict image upload types also allow image to be null. Rails

In my Rails 2 application, images for products are uploaded using Paperclip as a plugin. I need to restrict the image types to jpeg and png and also allow saving of product even if image is not uploaded.

The current code is

has_attached_file :master_image,
  :url  => "/images/products/:id/private/master.img",
  :path => ":rails_root/public/images/products/:id/private/master.img"

validates_attachment_content_type :master_image, :content_type => ['image/png', 'image/jpg'] , :message => "image must be jpg or png." , :allow_nil => true

I added :allow_nil => true but it is not working.

I am getting image must be jpg or png when trying to save without image.

Any help????



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire