I'm new to rails and stuck on a problem I thought would be pretty straight forward. I would like to upload an image, resize it, and display the resized image. I can upload using carrierwave ok, but when trying to resize it and display it using mini_magick it all goes wrong! Based on the mini_magick docs I created a method in my class to resize the image like this;
class Item < ApplicationRecord
require "mini_magick"
mount_uploader :filename, ImageUploader
def resize_to_dev
output_file_name = "public/uploads/item/filename/" + "#{self.id}" + "/" + "#{self.id}" + ".jpg"
image = MiniMagick::Image.open(self.filename.current_path)
image.resize "100x100"
image.format "jpg"
image.write output_file_name
end
end
This resizes the image and renames it as the itemid.jpg. But if I try to display it using this code in my show template.
<p><% @item.resize_to_dev %>
<p><% output_file_dir = "public/uploads/item/filename/" + "#{@item.id}" + "/" + "#{@item.id}" + ".jpg"%>
<p><%= image_tag(output_file_dir, alt: 'Image')%>
I get the error;
'The asset "public/uploads/item/filename/2/2.jpg" is not present in the asset pipeline.'
even though the file is in that location.
There must be an easier way to do this! Any assistance is greatly appreciated.