更新:我已经切换到CarrierWave(终于得到它的工作),所以虽然我仍然欣赏这个问题的答案,我将无法尝试,如果他们真的工作,因为我已经完全删除DM-回形针从我的代码。如何使用Sinatra,Datamapper,DM-Paperclip和S3?
那里嗨,
我正在开发使用DataMapper的一个西纳特拉,web应用,并正在寻求与S3作为存储添加一些上传的功能。我试过CarrierWave,但我无法让它工作,所以现在我正在尝试dm-paperclip。这就是我现在所拥有的:
型号:
class Article
include DataMapper::Resource
include Paperclip::Resource
property :id, Serial
property :created_at, DateTime
property :updated_at, DateTime
property :title, String
property :body, Text
has_attached_file :screenshot,
:storage => :s3,
:s3_credentials => {
:access_key_id => 'my-access-key-id',
:secret_access_key => 'my-secret_access-key',
:bucket => 'my-bucket'
},
:styles => {
:medium => "300x300>",
:thumb => "100x100>"
}
end
控制器:
post '/articles/create' do
@article = Article.new
@article.title = params[:title]
@article.body = params[:body]
@article.screenshot = params[:screenshot]
begin
@article.save
rescue DataMapper::SaveFailureError => e
puts "Error saving article: #{e.to_s} validation: #{@article.errors.values.join(', ')}"
rescue StandardError => e
puts "Got an error trying to save the article #{e.to_s}"
end
redirect '/articles'
end
然而,当我创建一个新的文章不保存任何东西到我的S3存储和我不也不会有任何错误。
任何想法我做错了什么?
配置回形针抛出一个错误: “未初始化的常量ActiveSupport :: Inflector”(我没有使用ActiveSupport) – Marc 2011-03-13 12:45:47
好的,我会更新它,所以它不需要ActiveSupport。 – solnic 2011-03-14 13:11:24