0

I'm trying to implement a feature into one of my forms that gives the user the option to either upload a picture from their local disk or input a URL (kind of how Facebook does it). Any ideas what would be the best way to implement this? I've been looking at Carrier Wave and Paperclip as potential options.

Thanks

Rob
  • 7,028
  • 15
  • 63
  • 95
  • "Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: [Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist)" – the Tin Man Oct 11 '13 at 19:29

2 Answers2

2

Paperclip does all of this for you. I've used it several times and highly recommend it.

CDub
  • 13,146
  • 4
  • 51
  • 68
  • Any suggestions on how I could set this up within a form using paperclip? I can't seem to find any tutorials on giving the user an option to upload vs input a url – Rob Oct 11 '13 at 19:24
  • 1
    Your wish is my command. `f.file_field :image` ... See: http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails.html – CDub Oct 11 '13 at 19:28
  • haha thank you. As far as I can tell though in the tutorial they only talk about file uploads, but nothing on pulling files from URLs (aka. User likes a photo from another website so they just take the photo's URL and type it into a text box). Anything on that - or more specifically, how to make them both play well together? – Rob Oct 11 '13 at 19:33
  • 1
    Ah, sorry, I totally misread your earlier comment... Check this out: http://stackoverflow.com/questions/4049709/save-image-from-url-by-paperclip I've personally used the second answer. As for making them play together, you'd have to pick one that would trump the other in case a user fills out both the file chooser and the URL, otherwise you can set up your controller to check both fields for an image. – CDub Oct 11 '13 at 19:36
0

In case someone is looking at this in the future, here's an amazing rails cast on how to do this using Carrier Wave. Super simple!

http://railscasts.com/episodes/253-carrierwave-file-uploads?view=comments

Rob
  • 7,028
  • 15
  • 63
  • 95