我尝试了不同版本的aws-sdk gem和paperclip / paperclip-aws gems,但这个错误不会消失:
ActionView::Template::Error (uninitialized constant Paperclip::Storage::Aws::VERSION):
和
Extracted source (around line #25):
<td><b><%= article.title %></b></td>
<td><%= simple_format h(article.text) %></td>
<td><i><%= link_to article.attachment_file_name, article.attachment.url(:original, false) %></i></td>
</tr>
在任何地方都是库错误吗?
这是我的Gemfile摘录,来自评论的问题:
#Paperclip
gem 'paperclip', git: 'git://github.com/thoughtbot/paperclip.git'
gem 'aws-sdk', '~> 2.0'
gem 'aws-sdk-resources', '~> 2'
gem 'paperclip-aws'
更新
我必须在heroku生产中像这里db:reset一样清理数据库并删除本地机器上的sqlite文件。然后同样的Aws::VERSION
错误来自我的ArticlesController:
Extracted source (around line #24):
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
参数如下:
Parameters:
{"utf8"=>"✓", "authenticity_token"=>"FpE3KDmkv6ofsavuUiAynp9H9o31w+EYAh/ONQfuTHLDl+7EjfucF4kxn+ XHzwHJsdOMrPJ+7Sm8oVEg5PzxqA==",
"article"=>
{"title"=>"test7",
"text"=>"",
"attachment"=>
#<ActionDispatch::Http::UploadedFile:0x9653310
@content_type="text/plain",
@headers="Content-Disposition: form-data; name=\"article[attachment]\"; filename=\"HRNG.txt\"\r\nContent-Type: text/plain\r\n",
@original_filename="HRNG.txt",
@tempfile=#<File:C:/Users/Lap127/AppData/Local/Temp/RackMultipart20170202-9024-2uphpe.txt>>},
"commit"=>"Create Article"}
现在出现错误消息:
NameError (uninitialized constant Paperclip::Storage::Aws::VERSION):
我在更改属性时添加了我的app / models / article.rb以更改错误,例如: G。 :bucket
至:s3_bucket
class Article < ApplicationRecord
has_many :comments, dependent: :destroy
validates :title, presence: true,
length: { minimum: 5 }
has_attached_file :attachment,
:path => 'assets/:class/:attachment/:id/:style/:filename',
:storage => :s3,
:s3_bucket => ENV['AWS_BUCKET'],
:s3_permissions => 'public_read_write',
:s3_protocol => 'https',
:s3_host_name => 'eu-central-1.amazonaws.com',
:s3_host_alias => 'eu-central-1.amazonaws.com',
:s3_region => ENV['AWS_REGION'],
:s3_credentials => { :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_KEY_ID'],
:endpoint => 'eu-central-1.amazonaws.com' }
# Explicitly do not validate
do_not_validate_attachment_file_type :attachment
#validates_attachment :attachment, content_type: { content_type: 'application/x-java-archive'}, size: { in: 0..10.megabytes }
end
答案 0 :(得分:0)
我不知道哪个改变解决了这个问题。但我删除了paperclip-aws gem,因为它自4年以来一直没有活动,而paperclip v2 gem包括aws-sdk支持。然后我添加了两个变量:
:bucket => ENV['AWS_BUCKET'],
:s3_bucket => ENV['AWS_BUCKET'],