I'm using CarrierWave and Cloudinary to upload multiple pictures to my blogposts. I upload them from my browser.
This happens with the use of a file field in the post
form.
<%=file_field_tag "images[]", type: :file, multiple: true %>
When the form is being submitted, a picture
instance is created for each one of the images and the image is being uploaded to Cloudinary.
def create
@post = Post.new(post_params)
if @post.save
if params[:images]
params[:images].each do |image|
@post.pictures.create(image: image)
Cloudinary::Uploader.upload(image)
end
end
end
end
The ImageUploader I use is almost default (exept for including the cloudinary plugin)
class ImageUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
Now, the image is being saved to my server, and the image is being uploaded to cloudinary. But somehow the public_id's
never match. Does anyone understand why not? Is there a new public_id
created when I call Cloudinary::Uploader.upload(image)
?