Posted over 3 years ago. Visible to the public.
Basic file uploads and image versions
Goals
- Learn to treat files as an ActiveRecord attribute type, like
:string
or:integer
Research
- Look at the README for the
paperclip
gem - Look at the README for the
carrierwave
gem - Understand some advantages of CarrierWave over Paperclip
- Read about Common mistakes when storing file uploads with Rails
Exercise
In MovieDB, allow movie authors to upload a movie poster using the carrierwave
gem:
- The poster should be uploaded in the form where we can also fill in title, year, etc.
- On the movie show view, render a poster version that is 400 pixel wide, with a height that respects the aspect ratio of the original image
- On the movie index view, render a poster version that is 100 pixel wide and cropped to 100 pixel height, regardless of the original aspect ratio
- On the movie show view, offer a link to download the original poster image file.
- When editing a movie, offer controls to delete or replace the poster image file.
You do not need to treat movie posters as confidential, so it's not important if an unauthorized user can see a poster.
Make sure to add integration tests for adding, changing and deleting a poster image.