Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Example of automatic ajax upload of an attachment in a form using paperclip and Rails 2.3.5.
JavaScript Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app
config
db
doc
public
script
test
vendor/plugins/paperclip
.gitignore
README.md
Rakefile

README.md

Paperclip, Rails, and Automatic AJAX Upload of an Attachment

This is a sample Rails app that has one model that has an attachment: Workout. In the Workout form, users can attach a picture. The picture is immediately uploaded to the server and a preview image shown. When the workout form is submitted, the uploaded picture is attached to the new workout record.

This is an interesting case because the attachment is uploaded before the form is submitted. What is Paperclip supposed to attach it to?

The solution in this example is to use a model designed to hold these uploaded photos: TempPhoto.

It is unavoidable that some TempPhoto records don't get cleaned up. A rake task should be created to delete all old TempPhoto records and their files. This example app isn't robust enough to include all the bells and whistles that a production-ready app will need.

Something went wrong with that request. Please try again.