Skip to content

Instantly share code, notes, and snippets.

@laurenhavertz
Last active December 20, 2015 18:29
Show Gist options
  • Save laurenhavertz/6175996 to your computer and use it in GitHub Desktop.
Save laurenhavertz/6175996 to your computer and use it in GitHub Desktop.
RUBY GEMS

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
  1. rails new paperclip demo
  2. add gems to the Gemfile gem 'paperclip' gem 'aws-sdk'
  3. create a new bucket on Amazon
  4. In ENV/Production.rb & ENV/Development.rb
  • add keys
  • `:s3_host_name => 's3-us-west-1.amazonaws.com'' (specify host name for Northern California)
  1. bundle install

  2. rails g scaffold users name

  3. rake db:migrate

  4. In user model add "avatar" as attr_accessible has_attached_file :avatar, styles: { thumb: '100x100>' square: '200x200#' medium: '300x300>' }

  5. rails g migration AddAvatarToUsers

  6. to new migration file add_attachment :users, :avatar

  7. views/user/form add <%= f.label :avatar %> <%= f.file_field :avatar %>

  8. In views/show add <%= image_tag @user.avatar.url(:square) %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment