Jump to content

The ultimate community for Ruby on Rails developers.


Photo

PaperClip / CarrierWave / Other?

advice tutorial beginner

  • Please log in to reply
4 replies to this topic

#1 Jemagee

Jemagee

    Inspector

  • Members
  • 62 posts

Posted 15 August 2013 - 06:13 PM

One of my numerous projects is a project for a former coworker/friend who has started her own small natural food brokerage firm for smaller companies.  In the natural food industry there are quite a few documents, certifications that you have to provide to a variety of stores/distributors etc...to get them to carry your product.  My friend has asked that the first thing I set up for functionality is a way to upload these various documents and tag them to a specific client.  In the present there should be no limitations to who can see these docs when they are logged in but in the future 'permissions' to see certain files might be required as I integrate the idea of 'group share' budget prosposals being online so easy to edit and get approval and such.

 

What I feel I'll need from the gem I use

 

1.  Size and File Type limitations.  Really, I need to teach these people how to upload only PDF's, but product images probably would be a good idea as well, so JPGS too.

2.  Tagging multiple documents to a given 'user' - i know this is a model set up - but in watching the tutorials on railscast I got the feeling that it might be that only one upload could be tagged to a given user...maybe I misunderstood it.

3.  Easy dowanload set up

4.  Icon representation based on the file extension

5.  Compatiable with Amazon cloud storage - that seems the easiest most cost effective way to deal with this in the beginning

 

In my research I've discovered that the two most popular and well maintained 'upload' systems are the PaperClip Gem and the CarrierWave Gem.  I was hoping to get input from people experience with both or either about their strengths and weaknesses?



#2 Kelli Shaver

Kelli Shaver

    Inspector

  • Administrators
  • 75 posts
  • LocationKentucky

Posted 15 August 2013 - 06:30 PM

I've never used CarrierWave but Paperclip is really flexible. I've used it locally, with S3, with and without a database, and with some pretty custom paths and URLs and it's always worked fine. You'll have to manage your own tagging/permissions (shouldn't be hard, just set up a many-to-many relationship between them), but Paperclip should work well. The S3 integration is super easy. 



#3 noz

noz

    Signalman

  • Members
  • 21 posts

Posted 15 August 2013 - 09:33 PM

What I feel I'll need from the gem I use

 

1.  Size and File Type limitations.  Really, I need to teach these people how to upload only PDF's, but product images probably would be a good idea as well, so JPGS too.

2.  Tagging multiple documents to a given 'user' - i know this is a model set up - but in watching the tutorials on railscast I got the feeling that it might be that only one upload could be tagged to a given user...maybe I misunderstood it.

3.  Easy dowanload set up

4.  Icon representation based on the file extension

5.  Compatiable with Amazon cloud storage - that seems the easiest most cost effective way to deal with this in the beginning

 

 

With PaperClip:

 

1. Paperclip gives your model access to a attachment size validation, e.g.,:

validates_attachment_size :attachment, :less_than => 100.megabyte

You can use a custom validation for the file type, something like this aughta do it:

def extension_type
  valid_extensions = ["pdf","jpg","..."]
  unless ["pdf","jpg","..."].include?(File.extname(attachment).gsub(".",""))
    errors.add(:attachment,"File format is invalid. Valid file types include: #{valid_extensions.join(",")}.")
  end
end

2. There's third-party gems for tagging, https://github.com/m...-as-taggable-on seems really easy to setup. If you want users to have multiple uploads simply create a seperate Upload model and put all the paperclip/tagging logic in there, then setup the relationships such that user has many uploads and upload belongs to user.

3. Just setup a custom controller action and then use send_file.

4. You'll have access to a file_name column that paperclip adds in your model. Just setup a custom helper method that takes a file name argument and figure out what class you need to spit out.

5. I haven't done this, but I'm pretty sure there was a RailsCast on this, google around a bit.  :)

 


  • james likes this

#4 burmjohn

burmjohn

    Passenger

  • Members
  • 5 posts

Posted 15 August 2013 - 11:12 PM

The gem fog works with both paperclip and carrierwave which will let you use pretty much any online storage needed. I prefer carrierwave, its super flexible, works well, and simple to use.

Sent from my Nexus 7 using Tapatalk 4
  • james likes this

#5 AstonJ

AstonJ

    Dispatcher

  • Members
  • 35 posts

Posted 16 August 2013 - 12:41 AM

I gave carrierwave a shot after Ryan spoke highly of it in Railscasts - worth checking out: http://railscasts.co...ve-file-uploads 


:)






Also tagged with one or more of these keywords: advice, tutorial, beginner

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users