You may know that I've been working on Be The Builders for a while now. When it came time to build in some functionality for file uploads, I just started to cringe. I searched for a while on ways to get it done, but I was hoping for something a little easier without the need for middleware. I came across Plupload and figured I'd give it go for integrating into Rails 3. Ultimately, it was pretty easy and painless. I'll walk you through the process. Just to note, I was using CarrierWave to handle the file uploads on the Rails side and Mongoid as my ORM.
- Step 4 - Get your CarrierWave uploader mounted to your model. In this example, this is what I have: Now if you're using Rails 3 like I am, make sure you do a require 'carrierwave' and require 'carrierwave/orm/mongoid' at the top of your application.rb file. Also, you'll have to pull the latest code from github. At the time of this writing, the carrierwave gem does not support Rails 3.
- Step 5 - Code up the create action in your controller. It could be something as simple as this: Mine doesn't look that that, it's a little messy and I didn't want to paste all of it here.
- Step 6 - Relax and have a much deserved drink. You're done!
I found this process to be extremely easy and with Plupload I now have the option to use many different methods (flash, silverlight, html5, etc) to get files uploaded to Rails. Hope this quick tutorial helps you guys.
Posted 6/01/2010 09:00:00 AM - rails