NameError(未初始化的常量回形针::存储:: S3 :: AWS):回形针、常量、初始化、NameError

2023-09-11 23:50:37 作者:太酷不给撩

我试图将图像转换成我的web应用程序,我不断删除了不少功能后,遇到了这个错误。它来到了我的创造的应用程序控制器,我不能完全肯定,我应该何去何从。

  2015-02-06T20:30:12.292187 + 00:00的应用程序[web.1]:(1.9ms)ROLLBACK
2015-02-06T20:30:12.296299 + 00:00的应用程序[web.1]:NameError(未初始化的常量回形针::存储:: S3 :: AWS):
2015-02-06T20:30:12.296301 + 00:00的应用程序[web.1]:应用程序/控制器/ articles_controller.rb:24:在'创造'
2015-02-06T20:45:14.691084 + 00:00的应用程序[web.1]:[曲别针]节能/articles/images/000/000/013/original/git.jpeg
2015-02-06T20:45:14.698744 + 00:00的应用程序[web.1]:已完成500内部服务器在584ms错误
2015-02-06T20:45:14.700871 + 00:00的Heroku [路由器]:在=信息的方法= POST路径=/篇主机= preston.herokuapp.com REQUEST_ID = d9d02257-3616-4686,bce5- 3d912cd528c2 FWD =76.22.102.38赛道= web.1连接为1ms服务= 698ms状态= 500字节= 1754
 

Articles_controller.rb

 类ArticlesController<的ApplicationController
http_basic_authenticate_with名称:姓名,密码:密码,除了:[:索引:显示广告]

    高清指数
        @articles = Article.all.order(created_at DESC)
    结束

    高清节目
        @article = Article.find(PARAMS [:ID])
    结束

    高清新
        @article = Article.new
    结束

    高清编辑
        @article = Article.find(PARAMS [:ID])

    结束

    DEF创建
        @article = Article.new(article_params)

        如果@ article.save
          redirect_to时@article
        其他
            使新
        结束
    结束

    DEF更新
        @article = Article.find(PARAMS [:ID])

        如果@ article.update(article_params)
            redirect_to时@article
        其他
            渲染编辑
        结束
    结束

    DEF破坏
        @article = Article.find(PARAMS [:ID])
        @ article.destroy

        redirect_to时articles_path
    结束

    私人

    高清article_params
        params.require(:文章).permit(:标题:文本:图片)
    结束
结束
 

的Gemfile

 来源https://rubygems.org
红宝石2.0.0

创业板导轨,4.2.0
创业板上海社会科学院护栏,GT〜&; 5.0
创业板uglifier','> = 1.3.0'
创业板咖啡轨,GT〜&; 4.1.0
创业板的jQuery护栏
创业板turbolinks
创业板的JBuilder,GT〜&; 2.0
创业板自举 - 萨斯,GT〜&; 3.3.3
创业板自prefixer护栏
创业板曲别针,〜> 4.2.1
创业板AWS-SDK','〜> 2.0.22

组:开发:测试做
 创业板byebug
 宝石的Web控制台,GT〜&; 2.0
 创业板的春秋
 宝石'sqlite3的'
结束

组:生产做
    创业板PG
    创业板rails_12factor
结束

组:DOC做
    创业板SDOC','〜> 0.4.0,要求:假的
结束
 
存储控制器无法初始化怎么办

解决方案

修改您的Gemfile的AWS-SDK来之前2.0安装的版本:

 宝石AWS-SDK','< 2.0
 

这个问题是引入的AWS-SDK新版本(2.0+)。你可以点击这里阅读:http://ruby.awsblog.com/post/TxFKSK2QJE6RPZ/Upcoming-Stable-Release-of-AWS-SDK-for-Ruby-Version-2

I'm trying to incorporate images into my web app and I keep running into this error after removing quite a few features. It came down to my 'create' application controller and I'm not entirely sure where I should go from here.

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

解决方案

Modify your Gemfile's aws-sdk to install a version prior to 2.0:

gem 'aws-sdk', '< 2.0'

This issue was introduced with new version of aws-sdk (2.0+). You can read more here: http://ruby.awsblog.com/post/TxFKSK2QJE6RPZ/Upcoming-Stable-Release-of-AWS-SDK-for-Ruby-Version-2