如果你沒有一個S3帳戶已經去得到一個位置:
http://aws.amazon.com/s3/
您需要添加到您的接觸模型:
應用程序/模型/ contact.rb
has_attached_file :picture,
:styles => {:large => "275x450>"},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "appname/:attachment/:style/:id.:extension"
確保你應用程序的名字就是你的軌道在Heroku應用程序名稱。並確保您將圖片重命名爲任何您命名的圖片。
然後你需要一個配置文件在config/s3.yml
。
development:
bucket: bucked_name
access_key_id: key
secret_access_key: secret
production:
bucket: bucked_name
access_key_id: key
secret_access_key: secret
請確保您獲得正確的密鑰和密碼。
在你的寶石文件請確保您有這些寶石安裝:
gem "aws-s3", :require => "aws/s3"
gem "paperclip"
然後在你的表格,你需要一個文件域並聲明形式多:
<% form_for(@contact, :html => {:multipart => true}) do |f| %>
<p><%= f.file_field :picture %></p>
<% end %>
而且應該做的它。 如果你沒有一個S3帳戶已經去得到一個位置:
http://aws.amazon.com/s3/
您需要添加到您的接觸模型:
應用程序/模型/ contact.rb
has_attached_file :picture,
:styles => {:large => "275x450>"},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "appname/:attachment/:style/:id.:extension"
請確保您的appname是您在heroku上的rails應用程序名稱。並確保您將圖片重命名爲任何您命名的圖片。
然後你需要一個配置文件在config/s3.yml
。
development:
bucket: bucked_name
access_key_id: key
secret_access_key: secret
production:
bucket: bucked_name
access_key_id: key
secret_access_key: secret
請確保您獲得正確的密鑰和密碼。
在你的寶石文件請確保您有這些寶石安裝:
gem "aws-s3", :require => "aws/s3"
gem "paperclip"
然後在你的表格,你需要一個文件域並聲明形式多:
<% form_for(@contact, :html => {:multipart => true}) do |f| %>
<p><%= f.file_field :picture %></p>
<% end %>
然後郵寄您的聯繫與圖片。你說你正在使用rails 3?
您的聯繫模型
所以:
class Contact << ActiveRecord::Base
before_save :mail_user
def mailer_user
ContactMailer.contact_notification(@user).deliver
end
end
然後在你的郵件(假設你是在Rails 3中):
class ContactMailer < ActionMailer::Base
default :from => "[email protected]"
def contact_notification(@user)
@subscription = "test"
@url = "test"
mail(:to => "[email protected]",
:subject => "Test")
end
end
因此,在您郵件視圖,您需要包括和圖像標記像所以:
<%= image_tag(@contact.picture(:small)) %>
然後,你只需要在創建聯繫人後發送給你電子郵件,幷包括在tachment。
可笑的長答案決不會解決OP的問題。 – 2012-11-16 04:37:23