In my previous rails apps, I used gravatar_for method to link the gravatar to users. In a recent app, I wanted to add cover photos to the books and allow users to upload the images.
So I decided to use paperclip after seeing one of the episode of railscast. Instead of applying the plugin, I installed paperclip gem.
gem "paperclip", "~> 4.2" to Gemfile and run
Then add photo columns to the existing books table.
rails g migration AddPhotosToBooks
This will insert four columns into books table: photo_file_name, photo_file_size, photo_content_type, photo_updated_at.
Add the following lines to Book Model:
Forms to be updated:
And the updated book’s show view with the uploaded photo.
Besides, in order to run paperclip, ImageMagick is required. We can simply install it by homebrew.
brew install imagemagick
However, when I installed homebrew, several issues came out.
It was a long story, briefly speeking, I ran
brew doctor and tried to solve the warning issues by searching the net. Basiclly, I updated Git and Command Line Tool and reinstall the homebrew.