crsde
crsde

Reputation: 162

Ror + Paperclip: Why not work?

I've installed paperclip to my project as plugin using ruby script/plugin install http://github.com/thoughtbot/paperclip.git

Model:

class Company < ActiveRecord::Base
   has_attached_file :logo, :styles => { :large => "300x300>", :medium => "100x100>", :thumb => "50x50>" }
   validates_attachment_content_type :logo, :content_type => image/jpeg, :message => "Incorrect logo file type!"
   validates_attachment_size :log, :max => 200, :message => "big file" 
end

But controller methods returns: NoMethodError in CompaniesController#new undefined method `has_attached_file' for #

If i try to "require 'paperclip' " before model class, returned: MissingSourceFile in CompaniesController#new no such file to load -- paperclip

What is the problem?

Upvotes: 1

Views: 1310

Answers (4)

toashd
toashd

Reputation: 1002

Could be due to missing ImageMagick installation. Paperclip uses ImageMagick to process images. To properly use paperclip ensure that ImageMagick is installed and paperclip has access to it:

Install ImageMagick (if you're on Mac OS X):

brew install imagemagick

Tell paperclip where to find imagemagick, add

Paperclip.options[:command_path] = '/usr/local/bin/'

to your config/environments/development.rb

Hope this helps.

Upvotes: 0

DanneManne
DanneManne

Reputation: 21180

Since you have installed paperclip as a plugin, verify that it has actually been placed at the correct path in your app. It seems unlikely that it wouldn't be correct but I prefer to troubleshoot by checking what is working instead of what is not working :)

You should have a folder structure like this:

RAILS_ROOT/vendor/plugins/paperclip/lib/paperclip.rb

When it looks like this, rails should load paperclip.rb by default at every restart of the server. That is unless the app is configured NOT to load all plugins by default. Those configurations can be found in config/environment.rb

I would look for any entry like the following:

config.plugins ...
config.plugin_paths ...
config.plugin_locators ...
config.plugin_loader ...

If you find any entry like those, that might be the cause of the problem.

Upvotes: 1

jonesbp
jonesbp

Reputation: 363

Adding the line:

config.gem "paperclip"

To 'config/environment.rb' should solve this problem assuming the gem has been installed.

Upvotes: 0

jpemberthy
jpemberthy

Reputation: 7533

The paperclip Railscast is a great source to start playing with paperclip, try following those steps and let us know if your problem persists.

Upvotes: 1

Related Questions