http://wine4u.seesaa.net/article/170193214.html
Gemfileに以下を追加
gem 'paperclip'
gem 'aws-s3'
config/s3.ymlを作成
development:
bucket: myappdevelopment
access_key_id: your key
secret_access_key: your key
test:
bucket: myapptest
access_key_id: your key
secret_access_key: your key
production:
bucket: mosolab
access_key_id: KEY_ID
secret_access_key: ACCESS_KEY
画像を関連させるモデルに以下を追加
#http://rdoc.info/github/thoughtbot/paperclip
has_attached_file :photo, Proc.new {
if RAILS_ENV == 'production'
{
:styles => {:thumb => "50x50", :medium => "100x100", :large => "500x500"},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/profiles/:id/:style.:extension",
:url => ":s3_domain_url",
:bucket => 'mosolab'
}
else
{
:styles => {:thumb => "50x50", :medium => "100x100", :large => "500x500"},
:url => "/images/MODELs/:id/p_:style.:basename.:extension",
:path => ":rails_root/public/images/MODELs/:id/p_:style.:basename.:extension"
}
end
}.call
Viewを書き換え
<%= form_for @MODEL , :html => { :multipart => true } do |f| %>
(form内に追記)
<%= f.file_field :photo %>