Had encountered few has_attached_file errors because my use of the paperclip was not correct. I was using has_attached_file from the controller and not from the model.
So when has_attached_file undefined error is raised. Make sure you use if from models (and not from your controllers)...
has_attached_file :photo, :styles => { :medium => "300x300>"}
I got below error, it seems not working .
Photo C:/DOCUME~1/indian/LOCALS~1/Temp/stream,2524,.jpg is not recognized by the 'identify' command.
I am using Rails 3.0, Windows XP OS
rmagick-2.12.0-x86-mswin32
ImageMagick-6.5.6-8-Q8
got this message:
DEPRECATION WARNING: RAILS_ROOT is deprecated! Use Rails.root instead. (called from expand_path at /usr/lib/ruby/gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip.rb:39)
I got Paperclip to work for me... I wrote up my experiences in case that helps anyone else: http://patshaughnessy.net/2010/5/23/how-to-install-paperclip-in-a-rails-3-app
I was originally getting the dreaded NoMethodError & undefined method 'has_attached_file', but jyurek has committed a fix for this on May 19th on the paperclip rails 3 branch.
See the commit here:
http://github.com/thoughtbot/paperclip/commit/aa93daec50c35a7d8aa861e6ba5c980fdb4e618a
Now I'm no longer getting that error, and my models appear to be created just fine.
So... here's what I've learned - if you install (and I'm talking about git://github.com/thoughtbot/paperclip.git rails3 branch) ...
-if you install it as a plugin you get the functionality but not the generator
-if you install it as a gem you get the generator but you don't get the methods.
but of course neither works because of
can't convert nil into Integer
vendor/plugins/paperclip/lib/paperclip/processor.rb:46:in `sprintf'
vendor/plugins/paperclip/lib/paperclip/processor.rb:46:in `make_tmpname'
I tracked down a line in paperclip that breaks the entire module, which is the reason for has_attached_file being undefined is because there's a line it referring to Paperclip::CallbackCompatibility::Rails20 (which is undefined) breaking the entire Paperclip module.
I was able to comment out the affected lines and no longer had to manually include the module.
I'm still getting a can't convert nil to String in one of the temp name functions...
-- user.rb
require 'paperclip'
class User < ActiveRecord::Base
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
-- rails (server, generate, whatever) blarfs out with a method not found exception
/Users/wgray/.rvm/gems/ruby-1.8.7-p249/gems/activerecord-3.0.0.beta3/lib/active_record/base.rb:1141:in `method_missing': undefined method `has_attached_file' for # (NoMethodError)
from /Users/wgray/Documents/Sources/Rails/zblog/app/models/user.rb:14
from /Users/wgray/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:415:in `load'
from /Users/wgray/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:415:in `load_file'
from /Users/wgray/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:523:in `new_constants_in'
Adding 'include Paperclip' to user.rb as some have suggested results in a different error, one with an uninitialized constant.
I'm on Snow Leopard, Rails 3.0.0.beta3, and ruby 1.9.2dev (2010-04-03 trunk 27199) [x86_64-darwin10.3.0]
After installing the gem, I tried to generate a model, and got the error below.
$ rails generate model UserPhoto caption:string private:boolean main:boolean user_id:integer
.rvm/gems/ruby-head/gems/bundler-0.9.24/lib/bundler/source.rb:209:in `rescue in rescue in block (2 levels) in load_spec_files': There was a LoadError while evaluating paperclip.gemspec. (Bundler::GemspecError)
Does it try to require a relative path? That doesn't work in Ruby 1.9.
I'm pretty new to all of this but I wonder if the problem I'm experiencing might be down to the switch of
directories generators are searched for in rails 3?
From what I can see they seem to have been moved from GEM_DIR/generators to GEM_DIR/lib/generators
Looking at the paperclip gem directory on my installation I did find a /generators folder but no
/lib/generators folder
I tried moving the contents of /generators to newly created /lib/generators folder and when I tried to run paperclip generator in my app it was found. However, I got the following error
[WARNING] Could not load generator "generators/paperclip/paperclip_generator" because it's a Rails 2.x generator, which is not supported anymore
But when I access a model from my app, I get an error that the 'has_attached_file' is not found. I'm guessing something isn't bootstrapping properly between the plugin and RoR3.beta.3
hi, I have a paperclip fork, you can try if it will work at your end, just change your Gemfile:
gem 'paperclip', :git => 'git://github.com/lmumar/paperclip.git', :branch => 'rails3'
Not any more.
My Gemfile has following line:
gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git', :branch => 'rails3'
I always get NoMethodError for `has_attached_file'
Does not generate images from styles, even when running 1.8.7. This commit fixes it: http://github.com/peterpunk/paperclip/commit/b13f7dffab5e323efb728546f4f8d85f121be569
Works like a charm in dev mode but give's me a real headache in production… When I run gem install && gem pack (in dev) the gem installs (Installing paperclip (2.3.1.1) from git://github.com/JasonKing/paperclip.git (at 9c90828)) but is never copied to vendor/cache…
Rails 3 uses bundler. Which means you dont run gem install and gem pack to handle dependencies.
Suggest you watch http://railscasts.com/episodes/201-bundler to catch up on the new ways of handling dependencies. Please note that bundler changes awfully fast though, so commands can change. But you'll get a hang of it.
I solved it temporarily though by installing Paperclip as a plugin and doing what this guy did:
http://stackoverflow.com/questions/2341216/rails3-and-paperclip
Will switch to the gem as soon things stable out in development. :)
No need to do those changes if you use JasonKing's repo. Those are already applied there. I for one prefer having the more dynamic approach with remote gems defined in my gemfile, and not using plugins.
At the same time you get the advantage of a smaller deployment-size.
If you wanna use Jasons repo for paperclip, just define this in your gemfile:
gem "paperclip", :git => "git://github.com/JasonKing/paperclip.git"
The callbacks aint broken in smathy's repo. It's the gems depending on paperclip that are broken. Since Rails3 changes how callbacks are handled and named.
Open issue-reports in the projects that are broken instead of naming Paperclip as the one and only problem.
Using the github.com/JasonKing/paperclip rails3 branch it works fine, a small change to the callbacks is all it take to make sure post processing thumbnails etc works again.
Works perfectly fine with this fork, thumbnails are generating nicely. Have only tested it on my local filesystem, no uploading to S3/CF or what have you.
I have installed the gem by bundling it:
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git", :branch => "rails3"
Then I execute:
bundle install && bundle pack.
I haven't tested the plugin at all yet. But tried to use his generator, and it doesn't work well. Like that:
rails generate paperclip Logo
Could not find generator paperclip.
I don't know if it is a gem issue or if it is issue of my environment.
though it's not working neither from gem nor from github plugin, after commenting out 283 line in the attachment.rb file (return if fire_events(:before)) it'll work (though I think that models' callbacks will be ignored)
My bad. I only tested :original and not the rest. Github's searchfunction in issues aint working right now, but I've seen a fix for the post_processing problem.
Paperclip works as long as you only use the :original.
Mirroring what I said in my patch - the new ActiveSupport::Callbacks in Rails3 had already broken the API that delayed_paperclip was depending on. It wasn't me.
delayed_paperclip (and any other gems or plugins that were using the old API) needs to use the new API - so something like: `set_callback :"#{name}_post_process, :before, :"halt_processing_for_#{name}"`