Search code examples
ruby-on-railsminimagick

Store uploaded images tdefinitely based on their json representation


Hello everyone since the past hour i've been trying to use minimagick gem, but i can't figure out why i can't open an image. the return value is always null

i have the following code in my controller:

class UploadController < ApplicationController
    require 'mini_magick'

    def load
        file = "public/uploads/cache/img.jpg"
        image = MiniMagick::Image.open(file)
        render json: image
    end
end

On a get to upload#load i get a null value.

i have installed minimagick on my mac using homebrew. i restarted the server.

Thanks!


Solution

  • You are rendering local variable "image" instead instance variable "@image"

    def load 
      file = "public/uploads/cache/img.jpg" 
      @image = MiniMagick::Image.open(file) 
      render json: @image 
    end