Search code examples
ruby-on-railsrubyruby-on-rails-5shrine

NameError: uninitialized constant Plaqueorder::ShrineImageUploader when using Shrine 2.8 on Rails 5.1.4


I cannot get Shrine to work no matter what I do and I am using the simplest of setups to start with.

db/schema.rb

create_table "plaqueorders", force: :cascade do |t|
    ...
    t.text "image_data"
    ...

initializers/shrine.rb

require 'shrine'
require 'shrine/storage/file_system'

Shrine.storages = {
cache: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/cache'),
store: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/store'),
}

Shrine.plugin :activerecord
Shrine.plugin :cached_attachment_data # for forms

uploaders/image_uploader.rb

class ShrineImageUploader < Shrine
end

models/plaqueorder.rb

class Plaqueorder < ApplicationRecord
  belongs_to :user
  validates :plaque_type, presence: true
  include ShrineImageUploader[:image]
end

Solution

  • Welp, to start with, it seems image_uploader.rb defines ShrineImageUploader. I would think the file would be named shrine_image_uploader.rb or the class would be named ImageUploader.

    Otherwise, you have a naming mismatch.