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
````
#
#
#
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.
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!
Most helpful comment
If your uploader is in the
app/uploadersfolder, 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.