简体   繁体   English

Heroku 上的 Rails 5 带有回形针和 aws 以及不同的 gem 版本

[英]Rails 5 on heroku with paperclip and aws and different gem versions

I tried different versions of aws-sdk gem and paperclip/paperclip-aws gems, but this error will not go away:我尝试了不同版本的 aws-sdk gem 和 paperclip/paperclip-aws gems,但这个错误不会消失:

ActionView::Template::Error (uninitialized constant Paperclip::Storage::Aws::VERSION):

and:和:

 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>

Is it a library error anywhere?任何地方都是库错误吗?

This is my Gemfile excerpt, question from the comments:这是我的 Gemfile 摘录,来自评论的问题:

#Paperclip
gem 'paperclip', git: 'git://github.com/thoughtbot/paperclip.git'

gem 'aws-sdk', '~> 2.0'
gem 'aws-sdk-resources', '~> 2'

gem 'paperclip-aws'

Update: I had to clean the database like here db:reset on heroku production and delete sqlite file on local machine.更新:我必须像这里的db:reset在 heroku 生产中清理数据库并删除本地机器上的 sqlite 文件。 Then the same Aws::VERSION error comes from my ArticlesController:然后同样的Aws::VERSION错误来自我的 ArticlesController:

 Extracted source (around line #24):

def create
  @article = Article.new(article_params)

  if @article.save
    redirect_to @article

And Parameters are as follows:和参数如下:

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"}

Error message now:现在的错误信息:

NameError (uninitialized constant Paperclip::Storage::Aws::VERSION):

I add my app/models/article.rb for the Error changes when changing attributes, eg :bucket to :s3_bucket我为更改属性时的错误更改添加了我的 app/models/article.rb,例如: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

I do not know which change solved the problem.我不知道哪个更改解决了问题。 But I removed paperclip-aws gem since it is not active since 4 years and paperclip v2 gem includes aws-sdk support.但是我删除了 paperclip-aws gem,因为它自 4 年以来一直不活跃,并且 paperclip v2 gem 包括 aws-sdk 支持。 Then I added both variables:然后我添加了两个变量:

:bucket => ENV['AWS_BUCKET'],
:s3_bucket => ENV['AWS_BUCKET'],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM