How to handle 'ActiveRecord::RecordInvalid Exception' while we upload image with 'carrierwave' gem through child of a class (STI) in ruby on rails?
'carrierwave' gem to upload image.
theses are my models:
class Content < ApplicationRecord validates_presence_of :file end
class Image < Content mount_uploader :file, ::ImageUploader end
I use postman to post image. and it's params field is
file While I try to create new Image, it returns
file = params[:file] ::Image.create(file: file)
#<Image:0x00007fddc6caaa48 id: nil file: nil,
then, it gives the following error:
*** ActiveRecord::RecordInvalid Exception: Validation failed: File can't be blank, File Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: You must have ImageMagick or GraphicsMagick installed
P.S: I have a lot of other fields, but I show only one file filed for understanding easily.
We need to install
libmagickwand-devin order to successfully complete the rmagick gem.
brew install imagemagick #on a mac
for other OS and more details look at this question ERROR Original Error: ImageMagick/GraphicsMagick is not installed