Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails NameError(未初始化的常量回形针::存储::S3::AWS):_Ruby On Rails_Ruby_Amazon Web Services_Paperclip - Fatal编程技术网

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

Ruby on rails NameError(未初始化的常量回形针::存储::S3::AWS):,ruby-on-rails,ruby,amazon-web-services,paperclip,Ruby On Rails,Ruby,Amazon Web Services,Paperclip,我正在尝试将图像合并到我的web应用程序中,在删除了很多功能后,我一直遇到这个错误。这取决于我的“创建”应用程序控制器,我不完全确定我应该从这里走到哪里 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)

我正在尝试将图像合并到我的web应用程序中,在删除了很多功能后,我一直遇到这个错误。这取决于我的“创建”应用程序控制器,我不完全确定我应该从这里走到哪里

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
文章\u 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的aws sdk以安装2.0之前的版本:

gem 'aws-sdk', '< 2.0'
gem'aws-sdk',“<2.0”

此问题是在aws sdk(2.0+)的新版本中引入的。您可以在此处阅读更多信息:

我通过导航到我的gem文件夹并将gem更改为:

  • 宝石“回形针”
  • gem'awsdk'
可以删除版本声明

为避免出现
gem.lock错误
,请运行
bundle update
而不是
bundle install
,否则只更新gems

现在,可以使用
heroku logs-t
命令监视heroku服务器的映像上载

我最初收到AWS服务器的一个新错误,
Access Denied error

为了解决这个问题,我在Amazon网站上找到了带有最新日期的
活动访问密钥ID
,并使用heroku命令输入最新的
访问密钥ID
秘密访问密钥

这使我能够在heroku上查看我的图像

为了解决这个问题,我制作了很多
访问密钥ID
秘密访问密钥
,但发现Gems才是真正的问题

提示:将您的所有访问密钥信息保存到OneNote、记事本等。这样,您可以返回并检查它们。

有正式的解决方案 使用此分支的回形针: 它适用于aws sdk 2以上版本

gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68'
只需将:s3\u region参数添加到曲别针s3配置中即可


适用于我

回形针用于使用4.3版及以下版本中的AWS-SDK v1。他们试图包括AWS-SDK v2

官方升级文件

由于某些向后不可比性(请阅读此内容),该文件已合并,但尚未正式发布,但应以回形针v
5.0.0

如前所述,您现在必须使用:

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

当曲别针5.0发布时,AWS-SDK v2应该包括在内

您是否部署到Heroku?是的,我已经部署了,我正在查看Heroku日志,发现了错误。很可能是因为您没有在Heroku中初始化AWS常量,你需要运行$heroku config:set S3\u BUCKET\u NAME=你的\u BUCKET\u NAME$heroku config:set AWS\u ACCESS\u KEY\ID=你的\u ACCESS\u KEY\ID$heroku config:set AWS\u SECRET\u ACCESS\u KEY=你的\u SECRET\u ACCESS\u keyhmm我确实遵循了这个步骤,但我会从头开始,只是为了确保它是正确的好的,让我知道它是否有效,这样我就可以为其他人解答这个问题了我发现原因在于更新的“aws sdk”gem。aws sdk的新版本(2+)与以前的版本不向后兼容。你可以多读一点谢谢,这正是我需要的!此外,您可以将该行替换为
gem'aws-sdk-v1'
。然后,这允许您拉入v2 aws sdk gem。由于名称空间不同,它们可以在同一个应用程序中一起使用。Trevor Rowe的解决方案对我来说非常有效——而且它们可以同时使用这一事实非常有用。谢谢特雷弗!我遇到了同样的问题,您是否通过删除版本解决了它?这是现在最好的答案,因为aws 1已被弃用。
##################################################
#  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`.
# Gemfile
# ...
gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68'