如果你没有一个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