简体   繁体   中英

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:

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:

#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. Then the same Aws::VERSION error comes from my 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

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. Then I added both variables:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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