Guide for the Upload Generator in Rails
Now that our image uploading libraries are in place, we can create our uploader. Carrierwave has a helpful generator that will setup a basic upload configuration file that we can use for our application.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Now that our image uploading libraries are in place, we can create our uploader. Carrierwave has a helpful generator that will setup a basic upload configuration file that we can use for our application.

To start, go to the command line and type:

rails g uploader Photo

large

This command will create a file called photo_uploader.rb and will place it in the uploaders folder in the app directory. You can also see this file in the sublime text editor, and this what it looks like.

large

This class inherits from CarrierWave and the system knows we are going to be using the CarrierWave gem because we built it into our application earlier.

For storage, it uses the local file system by default which means files will be save in your local machine. Since we want to store our image files on AWS, we have to change it, which we'll update in another lessons.

The store_dir method shows where files will be uploaded. Again, we have to have to change it, otherwise the application would get incredibly large.

We will replace all of this with our custom code in the next lesson.