CarrierWave and Rails 4

76 views
Skip to first unread message

Chris McCann

unread,
Sep 15, 2014, 7:43:06 PM9/15/14
to sdr...@googlegroups.com
SD Ruby,

I'm trying to use CarrierWave wave 0.10.0 in Rails 4.1.5 with Ruby 2.1.2.  This is my first time trying it out having been a PaperClip guy for a long time.

I can't seem to figure out what I need to do so my app can load an uploader out of the app/uploaders directory. 

The error I get when I try to create an instance of a model that uses mount_uploader is:

uninitialized constant SourceImage::SourceImageUploader

It seems pretty clear to me that the app hasn't loaded and can't find the stuff in the app/uploaders directory.  I do have a SourceImageUploader in the app/uploaders directory.

As I understand it adding paths to the autload_paths isn't thread-safe and is something Matz discourages.  There was a change in CarrierWave 0.8.0 that appears to have removed autoloading (if I'm reading the commit correctly).

I've been through the README and the wiki but I'll darned if I can figure out what I've done wrong or simply not done in setting up CarrierWave in my app. 

Any help would be appreciated!

Cheers,

Chris

John Lynch

unread,
Sep 15, 2014, 8:12:58 PM9/15/14
to sdr...@googlegroups.com
Chris, 

I have a working CarrierWave app, and in a console, when I say

Rails.configuration.eager_load_paths

I get a list of all my paths, including all folders under /app, i.e.  “/blah/app/uploaders”, etc.   I believe that Rails will load all those on startup, which means you need to restart your server to pick up any changes. The uploaders path is not in my Rails.configuration.autoload_paths

- john



--
--
SD Ruby mailing list
sdr...@googlegroups.com
http://groups.google.com/group/sdruby
---
You received this message because you are subscribed to the Google Groups "SD Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sdruby+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris McCann

unread,
Sep 15, 2014, 8:39:40 PM9/15/14
to sdr...@googlegroups.com, jly...@kaleosoftware.com
John,

Is this a development console or production?  If it's development, do you have config.cache_classes = true set?

Here's what http://edgeguides.rubyonrails.org/configuring.html says about the /app directory (emphasis added):

  • config.eager_load_paths accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the app directory of the application.

I don't have cache classes enabled in development.  If I go into the console in my app and output the eager_load_paths, I get:

["/Users/chris/rails/my_app/app/assets",

"/Users/chris/rails/my_app/app/controllers",

"/Users/chris/rails/my_app/app/helpers",

"/Users/chris/rails/my_app/app/mailers", 

"/Users/chris/rails/my_app/app/models",

"/Users/chris/rails/my_app/app/controllers/concerns",

"/Users/chris/rails/my_app/app/models/concerns"]

If I turn on cache_classes, the app/uploaders directory appears as well and CarrierWave works, but clearly I don't want to do that.  So for now, I've added this to my config/environments/development.rb file:

config.autoload_paths += Dir[Rails.root.join('app', 'uploaders').to_s]

Cheers,

Chris
To unsubscribe from this group and stop receiving emails from it, send an email to sdruby+unsubscribe@googlegroups.com.

John Lynch

unread,
Sep 15, 2014, 8:56:56 PM9/15/14
to sdr...@googlegroups.com
Huh, yea its the development console (Rails 4.1-stable) , and I have
 
# development.rb
config.cache_classes = false
config.eager_load = false

[42] pry(main)> Rails.configuration.eager_load_paths
=> ["/Users/john/Code/woot/app/assets",
 "/Users/john/Code/woot/app/controllers",
 "/Users/john/Code/woot/app/decorators",
 "/Users/john/Code/woot/app/helpers",
 "/Users/john/Code/woot/app/jobs",
 "/Users/john/Code/woot/app/mailers",
 "/Users/john/Code/woot/app/middlewares",
 "/Users/john/Code/woot/app/models",
 "/Users/john/Code/woot/app/operations",
 "/Users/john/Code/woot/app/uploaders",
 "/Users/john/Code/woot/app/models/concerns”]

[43] pry(main)> Rails.configuration.autoload_paths
=> ["/Users/john/Code/woot/app/observers",
 "/Users/john/Code/woot/app/middlewares",
 "/Users/john/Code/woot/app/jobs",
 "/Users/john/Code/woot/lib",
 "/Users/john/Code/woot/lib/woot/*",
 "/Users/john/Code/woot/app/operations"]


​- john


To unsubscribe from this group and stop receiving emails from it, send an email to sdruby+un...@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages