Guide to Image Uploading Gems in Rails
In this lesson, we are going to add some of the library files needed in order for our application to be able to: upload images, connect to the AWS S3 cloud storage service, and manage files.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this lesson, we are going to add some of the library files needed in order for our application to be able to: upload images, connect to the AWS S3 cloud storage service, and manage files.

Go to Gemfile and add a new section like this:

large

To install these gems, go to the command prompt and type:

bundle install

This will integrate all these gems into our application.

Now, let's talk a little bit on what each of these gems do.

  • CarrierWave is one the most popular gem for file uploads as it allows you to use its methods inside your controller to upload the files you want. To get more information, visit the documentation page at https://github.com/carrierwaveuploader/carrierwave.

  • MiniMagick is a cool gem that allows us to do a lot of different things such as handling file sizes and resizing images. We'll mostly be calling it from our uploader file. The documentation for this gem is available at: https://github.com/minimagick/minimagick.

  • Fog is a gem that allows us to connect to Amazon Web Services (AWS) CDN, which is where we are going to store all of our image files. AWS is a great place to store your files because it's easy for Heroku and other such services to use them. Also, it's free to sign up for an account. You can get more information about fog here: https://github.com/fog/fog.

  • Figaro is a great gem to implement security in your application. You probably don't want a lot of your files to be publicly available, so it protects your environment variables and makes it available only in your local machine and in your production environment so that you can access with a username and password. To learn more about this gem, go to https://github.com/laserlemon/figaro.

  • unf gives Unicode Normalization Form support to Ruby. We won't be using it extensively, but just to get protection from some issues that tend to occur while integrating carrierwave. To get detailed information on this gem, visit https://github.com/knu/ruby-unf.