PreReqs:
- install image magick
brew install imagemagick
<- in the terminal gem install paperclip
gem install aws-sdk
- think if you want 2 buckets: 1 for development and 1 for production
rails new paperclip demo
- add gems to the Gemfile
gem 'paperclip'
gem 'aws-sdk'
- create a new bucket on Amazon
- In ENV/Production.rb & ENV/Development.rb
- add keys
- `:s3_host_name => 's3-us-west-1.amazonaws.com'' (specify host name for Northern California)
-
bundle install
-
rails g scaffold users name
-
rake db:migrate
-
In user model add "avatar" as attr_accessible
has_attached_file :avatar, styles: { thumb: '100x100>' square: '200x200#' medium: '300x300>'
} -
rails g migration AddAvatarToUsers
-
to new migration file
add_attachment :users, :avatar
-
views/user/form add
<%= f.label :avatar %> <%= f.file_field :avatar %>
-
In views/show add
<%= image_tag @user.avatar.url(:square) %>