Processor not loading at first try with Rails3

98 views
Skip to first unread message

Alejandro Riera

unread,
Sep 16, 2010, 1:48:22 PM9/16/10
to Paperclip Plugin
Hello,

I'm having an issue when loading a processor for cropping images. The
first time it is called it breaks with this message:
[paperclip] An error was received while processing:
#<Paperclip::PaperclipError: Processor Jcropper was not found>
the following times it is used there is no problem, it works without
problem.

My box has paperclip 2.3.3 revision 9e6afe4 (according to my
Gemfile.lock) and rails 3.0.0 installed.

My processor (jcropper.rb) is located in lib/paperclip_processors and
I have put that path in the autoload paths in application.rb
[config.autoload_paths += %W(#{config.root}/lib/
paperclip_processors) ].

My guess is that gems/processors/models/dont-know-what-else are not
being required in the correct order, but I dont know which one it
might be and dont knowhow to face this problem, so I will thank any
help here : )

Just to clarify, the process is as follows:
1. Start webrick (OK)
2. Upload a photo (OK)
3. Crop that photo (ERROR)
4. Upload another photo (OK)
5. Crop that photo (OK)
repeat 4 and 5 and it will always work (until you stop the server and
relaunch it)

Thanks in advance,

Alex

Alejandro Riera

unread,
Sep 17, 2010, 12:53:01 PM9/17/10
to Paperclip Plugin
Apparently the problem is that paperclip [1] has this code

    if defined?(Rails.root) && Rails.root
      Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
        require processor
      end
    end

When bundler loads gems for the first time rails is not already loaded, so `Rails.root` won't be defined and paperclip won't require the processors.

My solution is quite ugly: I installed paperclip as a plugin and edited that file to manually require my processor like this:
require 'lib/paperclip_processors/jcropper'

Not the prettiest solution, but will fix the problem until the problem is properly addressed.

Cheers,

Alex

[1]: http://github.com/thoughtbot/paperclip/blob/master/lib/paperclip.rb


--
Individuals over processes. Interactions over tools.

Agile Rails training from thoughtbot, the makers of Paperclip, Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training

The Paperclip group:
http://groups.google.com/group/paperclip-plugin

To post to this group, send email to
papercli...@googlegroups.com

To unsubscribe from this group, send email to
paperclip-plug...@googlegroups.com



--
In the game of chess you can never let your adversary see your pieces.

Christian Fazzini

unread,
Oct 1, 2010, 5:47:34 AM10/1/10
to Paperclip Plugin
Hi Alex, I too am getting the same problem in Rails 3. Seems like
paperclip is not recognising the processor option in rails 3....

Its been a few days, do you have a better fix now?
> > paperclip-plug...@googlegroups.com<paperclip-plugin%2Bunsu...@googlegroups.com>

pconnordctt

unread,
Oct 1, 2010, 12:16:12 PM10/1/10
to Paperclip Plugin
I am curious if another solution has been found for this?

Christian Fazzini

unread,
Oct 1, 2010, 1:32:09 PM10/1/10
to Paperclip Plugin
So far, I have found this. I put it in application.rb

# Needed for paperclip: http://github.com/thoughtbot/paperclip/issues/issue/247
# The documentation states that custom processors that inherit
from Paperclip::Processor will be loaded
# automatically if placed in lib/paperclip_processors. But in
Rails 3, this isn't the case.
# This issue is caused by the Paperclip gem being loaded before
the Rails object is properly configured.
# Needs to be fixed properly in Paperclip itself.
config.after_initialize do

# copied from paperclip.rb: due to bundler, this doesn't seem to
happen automagically anymore!?!
Dir.glob(File.join(File.expand_path(Rails.root), "lib",
"paperclip_processors", "*.rb")).each do |processor|
require processor # PVDB don't rescue LoadError... let it rip!
end

end

jrs

unread,
Oct 1, 2010, 5:58:44 PM10/1/10
to Paperclip Plugin
Try sticking the cropper processor file inside /config/initializer
file.

On Oct 1, 10:32 am, Christian Fazzini <christian.fazz...@gmail.com>
wrote:

Christian Fazzini

unread,
Oct 2, 2010, 8:42:43 AM10/2/10
to Paperclip Plugin
jrs, is that how it is supposed to be though? or is this a temp
solution until paperclip gets it fixed?
Reply all
Reply to author
Forward
0 new messages