IT박스

NameError (초기화되지 않은 상수 Paperclip :: Storage :: S3 :: AWS) :

itboxs 2020. 9. 5. 09:29
반응형

NameError (초기화되지 않은 상수 Paperclip :: Storage :: S3 :: AWS) :


웹 앱에 이미지를 통합하려고하는데 몇 가지 기능을 제거한 후에도이 오류가 계속 발생합니다. 그것은 내 '생성'응용 프로그램 컨트롤러로 내려 왔고 여기서 어디로 가야할지 완전히 모르겠습니다.

2015-02-06T20:30:12.292187+00:00 app[web.1]:    (1.9ms)  ROLLBACK
2015-02-06T20:30:12.296299+00:00 app[web.1]: NameError (uninitialized constant Paperclip::Storage::S3::AWS):
2015-02-06T20:30:12.296301+00:00 app[web.1]:   app/controllers/articles_controller.rb:24:in `create'
2015-02-06T20:45:14.691084+00:00 app[web.1]: [paperclip] saving /articles/images/000/000/013/original/git.jpeg
2015-02-06T20:45:14.698744+00:00 app[web.1]: Completed 500 Internal Server Error in 584ms
2015-02-06T20:45:14.700871+00:00 heroku[router]: at=info method=POST path="/articles" host=preston.herokuapp.com request_id=d9d02257-3616-4686-bce5-3d912cd528c2 fwd="76.22.102.38" dyno=web.1 connect=1ms service=698ms status=500 bytes=1754

Articles_controller.rb

class ArticlesController < ApplicationController
http_basic_authenticate_with name: "name", password: "password", except: [:index, :show]

    def index
        @articles = Article.all.order("created_at DESC")
    end

    def show
        @article = Article.find(params[:id])
    end

    def new
        @article = Article.new
    end 

    def edit
        @article = Article.find(params[:id])

    end

    def create
        @article = Article.new(article_params)

        if @article.save
          redirect_to @article
        else
            render 'new'
        end  
    end

    def update
        @article = Article.find(params[:id])

        if @article.update(article_params)
            redirect_to @article
        else
            render 'edit'
        end
    end

    def destroy
        @article = Article.find(params[:id])
        @article.destroy

        redirect_to articles_path
    end

    private

    def article_params
        params.require(:article).permit(:title, :text, :image)
    end
end

Gemfile

source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '4.2.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'bootstrap-sass', '~> 3.3.3' 
gem 'autoprefixer-rails'
gem 'paperclip', '~> 4.2.1'
gem 'aws-sdk', '~> 2.0.22'

group :development, :test do
 gem 'byebug'
 gem 'web-console', '~> 2.0'
 gem 'spring'
 gem 'sqlite3'
end

group :production do
    gem 'pg'
    gem 'rails_12factor'
end

group :doc do
    gem 'sdoc', '~> 0.4.0', require: false
end

2.0 이전 버전을 설치하도록 Gemfile의 aws-sdk를 수정합니다.

gem 'aws-sdk', '< 2.0'

이 문제는 새 버전의 aws-sdk (2.0+)에서 발생했습니다. 자세한 내용은 http://ruby.awsblog.com/post/TxFKSK2QJE6RPZ/Upcoming-Stable-Release-of-AWS-SDK-for-Ruby-Version-2에서 읽을 수 있습니다.


공식 솔루션이 있습니다 .Use paperclip from this branch : it works with aws-sdk versions above 2

gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68'

종이 클립 s3 구성에 : s3_region 매개 변수를 추가하십시오.

나를 위해 일해


내 gem 폴더로 이동하여 Gems를 다음과 같이 변경하여 작동하도록했습니다.

  • gem ‘paperclip’
  • gem ‘aws-sdk’

The version declarations can be dropped.

To avoid getting a gem.lock error, run bundle update instead of bundle install, otherwise only the gems will be updated.

Now, the heroku logs -t command can be used to monitor the heroku server to image uploads.

I orginally received a new error, Access Denied Error for AWS server.

To fix this I found the Active Access Key ID with the latest date on the Amazon websiteand used heroku commands to input the latest Access key ID and Secret access key.

This enabled me to view my image on heroku.

I had made so many Access key ID and Secret access keys trying to fix the problem, but found the Gems to be the real problem.

Tip: Save all your Access Key info to OneNote, Notepad, etc. This way you can return and check them.


Paperclip use to use AWS-SDK v1 in versions 4.3 and bellow. They are trying to include the AWS-SDK v2

official upgrade document https://github.com/thoughtbot/paperclip/blob/master/UPGRADING

##################################################
#  NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER       #
##################################################

Paperclip is now compatible with aws-sdk >= 2.0.0.

If you are using S3 storage, aws-sdk >= 2.0.0 requires you to make a few small
changes:

* You must set the `s3_region`
* If you are explicitly setting permissions anywhere, such as in an initializer,
  note that the format of the permissions changed from using an underscore to
  using a hyphen. For example, `:public_read` needs to be changed to
  `public-read`.

due to some backwards incomparability (read this https://github.com/thoughtbot/paperclip/issues/2021) this is merged but officially not released yet, but should be released in Paperclip v 5.0.0

So like Vitali Mogilevsky mentioned, you have to use this for now:

# Gemfile
# ...
gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68'

When Paperclip 5.0 is released, AWS-SDK v2 should be included

참고URL : https://stackoverflow.com/questions/28374401/nameerror-uninitialized-constant-paperclipstorages3aws

반응형