Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attachment_fu or Paperclip for Rails3

I have just upgraded to rails3 and when I installed my usual attachment_fu plugin failed. So I started googling it and although I did manage to find a rails3 version there seemed to be a lot more people talking about paperclip with rails3.

So firstly what are the advantages of paperclip?

Is there better support for rails3 with it?

like image 596
DJ Forth Avatar asked Dec 14 '10 23:12

DJ Forth


3 Answers

Neither. Use carrierwave .

To handle the file uploads, I’ve switched from Paperclip to CarrierWave. While Paperclip has (and continues) to serve me well in many applications I work with, I really appreciate the modular approach that CarrierWave takes. It’s agnostic as to which of the popular S3 clients you use, supporting both aws/s3 and right_aws. It’s also ORM agnostic and not tightly coupled to Active Record. The tight coupling of Paperclip has caused us some grief at work, and I’m also confused about the state of Paperclip’s support for aws/s3 and right_aws. So, I was happy to find this new project, and the maintainer Jonas Nicklas seems to be an extremely responsive and helpful dude, which is always good thing. The code looks great, and I’ve had an easy time working with this library so far. (from: http://trevorturk.com/2010/2/8/kzak-an-open-source-web-based-jukebox/)

More info here:

  • http://techblog.moviepilot.com/carrierwave-as-a-replacement-for-paperclip
like image 69
bowsersenior Avatar answered Nov 19 '22 08:11

bowsersenior


I made attachment_fu rails3 compatible.

See https://github.com/mihael/attachment_fu

EDIT: but it is broken for some users, and i am not maintaining it further, so please look into other solutions, if you do not want to hack it yourself ;)

I tested paperclip vs carrierwave vs attachment_fu with rails3.0.3 for a project I am working on.

So far attachment_fu works very well as always, but the code still needs some refactoring with the callback system. It has backends for cloudfiles, s3.

Paperclip is also very good and is very easy to use. The basic setup did not let me upload movies (had to add option :whiny=>false), and it did not sanitize filenames the way I expected. This is how I did it:

class Asset < ActiveRecord::Base
  has_attached_file :file, :styles => { :small => "300x300>", :thumb => "50x50>" }, :whiny => false
  before_create :sanitize_file_name
  private
  def sanitize_file_name
    self.file.instance_write( :file_name,  file_file_name.gsub(/[^A-Za-z0-9\.\-]/, '_'))
  end  
end

Paperclip has s3 backend, but does not have a backend for cloudfiles built-in. There is a paperclip fork for that (google for paperclip-cloudfiles) which is built for rails2.3.5 (search github for paperclip_demo).

Carrierwave looks very nice, with the decoupled architecture, but I do not like the fact that it does not delete stuff on updates and destroys of objects, leaving a bunch of files and directories on disk. The basic carrierwave setup also did not let me upload movies, although it sanitizes filenames nicely. I did not found a quick fix for this, yet. If You are using Mongoid and GridFS, carrierwave has built in support.

Finally, I took Paperclip for my project.

like image 7
manitu Avatar answered Nov 19 '22 06:11

manitu


I've created a gem for attachment_fu if you want to continue using it in Rails 3.2 and beyond.

https://rubygems.org/gems/pothoven-attachment_fu

like image 2
Steven Pothoven Avatar answered Nov 19 '22 08:11

Steven Pothoven