Shrine: ameError: uninitialized constant Img::ImageUploader in console only

Created on 24 Nov 2016  路  6Comments  路  Source: shrinerb/shrine

  • Rails 5.0.0.1
  • Ruby 2.3.1
  • shrine 2.5.0

When uploading a file it works fine and generates an object, however when I enter rails c and call a new instance of my model Img.new I receive NameError: uninitialized constant Img::ImageUploader, yet this works from the browser.

config/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
````
img.rb

````

== Schema Information

#

Table name: imgs

#

id :integer not null, primary key

user_id :integer

image_data :text

created_at :datetime not null

updated_at :datetime not null

#

class Img < ApplicationRecord
include ImageUploader[:image]
belongs_to :user
end
````

app/uploaders/image_uploader.rb

class ImageUploader < Shrine end

Is there something I'm missing here? I followed the quick start guide and had no problems getting this this to work via the browser. If you need a stack trace or more information, please let me know.

Most helpful comment

If your uploader is in the app/uploaders folder, Rails should automatically pick it up, though it needs to be restarted in order to be able to pick up new folders.

Unless maybe you're using Spring, which didn't restart your application when you add a new folder. In that case I would recommend running spring stop, and then running the Rails console again.

I will close this, as this is just a file loading issue, and isn't related to Shrine.

All 6 comments

If your uploader is in the app/uploaders folder, Rails should automatically pick it up, though it needs to be restarted in order to be able to pick up new folders.

Unless maybe you're using Spring, which didn't restart your application when you add a new folder. In that case I would recommend running spring stop, and then running the Rails console again.

I will close this, as this is just a file loading issue, and isn't related to Shrine.

@janko-m You're right, it was spring all along. Stopped it and it picked up the class properly. Thanks for the help.

just as a side note... I experienced this as well in Rails 5.0.0.1 and shrine 2.5.0. spring stop/rails s resolved the issue.

Hi @janko I am having a problem with shrine latest and latest rails 6.0.3.4 ruby 2.7.2 and rails_admin gem 2.0.2

NameError in RailsAdmin::MainController#new
uninitialized constant ImageUploader::ImageProcessing

Here is a screenshot: error screen shoot

Here is my ImageUploader class: image_uploader

Tried already spring restart, puma restart.

@nezirz You need to require "image_processing/mini_magick"

Perfect! Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brunowego picture brunowego  路  4Comments

cilim picture cilim  路  10Comments

thib44 picture thib44  路  3Comments

technodrome picture technodrome  路  4Comments

Grafikart picture Grafikart  路  4Comments