Skip to content

Instantly share code, notes, and snippets.

@bridgpal
Created November 12, 2013 18:27
Show Gist options
  • Save bridgpal/7436150 to your computer and use it in GitHub Desktop.
Save bridgpal/7436150 to your computer and use it in GitHub Desktop.
Paperclip gem instructions

#Rails - Paperclip gem

##install

brew install imagemagick

##add gems

gem 'paperclip'
gem 'aws-sdk'

###development.rb/production.rb

  config.paperclip_defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => "wdi-paperclip",
    :access_key_id => "AKIAIGS4WPWXXXXXXXX",
    :secret_access_key => "hCz6YlZnYK8A5LhlXXXXXXXXXXX",
    :s3_host_name => 's3-us-west-1.amazonaws.com'
  }
}

####add data model

class User < ActiveRecord::Base
  attr_accessible :name, :avatar

    has_attached_file :avatar, styles: {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>'
  }

end


###create migration for avatars

rails g migration AddAvatarToUsers

  add_attachment :users, :avatar

###aadd avatars to your view

  <%= f.label :avatar %><br />
  <%= f.file_field :avatar %>

###add urls to show page

<%= image_tag friend.avatar.url(:square) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment