ruby-on-railsshrine

Where should I put shrine image_uploader file?


I'm using shrine for image uploading in my project. I'm trying to follow this guide: Getting Started/Eager Processing

I am not sure where should I put image_uploader.rb in my project.

FYI, here is the code for image_uploader.rb:

require 'image_processing/mini_magick'

class ImageUploader < Shrine
    Attacher.derivatives do |original|
        magick = ImageProcessing::MiniMagick.source(original)
        { 
          large:  magick.resize_to_limit!(1200, 1200),
          medium: magick.resize_to_limit!(640, 640),
          small:  magick.resize_to_limit!(180, 180),
        }
    end
end

It does not seem to belong to lib directory according to this answer(Rails lib directory) and this blog post(What Code Goes in the Lib/ Directory?).

And it is not a helper or a controller.

Where should I put it into?


Solution

  • I used to putting image_uploader.rb in uploaders folder, but usually doesn't exist folders so, you have to make folders, and I recommend these sample Getting started Shrine, Demo code

    yourapp/app/uploaders