我尝试将图片合并到我的网络应用中,并在删除了一些功能后继续遇到此错误。它归结为我的创造'应用程序控制器,我不完全确定我应该从哪里开始。
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
答案 0 :(得分:178)
修改您的Gemfile的aws-sdk以安装2.0之前的版本:
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
答案 1 :(得分:18)
有官方解决方案 使用此分支的回形针: 它适用于2以上的aws-sdk版本
gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68'
只需将s3_region参数添加到您的回形针s3配置
适合我
答案 2 :(得分:4)
我通过导航到我的gem文件夹并将Gems更改为:
来实现它可以删除版本声明。
为避免获得gem.lock error
,请运行bundle update
而不是bundle install
,否则只会更新宝石。
现在,heroku logs -t
命令可用于监控heroku服务器以映像上传。
我在AWS服务器上收到了一个新错误Access Denied Error
。
要解决此问题,我在亚马逊网站上找到了Active Access Key ID
最新日期,并使用heroku命令输入最新的Access key ID
和Secret access key
。
这使我能够在heroku上查看我的图像。
我已经做了很多Access key ID
和Secret access keys
尝试解决问题,但发现Gems是真正的问题。
提示:将所有访问密钥信息保存到OneNote,记事本等。这样您就可以返回并检查它们。
答案 3 :(得分:3)
Paperclip用于在版本4.3和下面使用AWS-SDK v1。他们正在尝试包含AWS-SDK v2
官方升级文件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`.
由于一些向后无法比较(阅读此https://github.com/thoughtbot/paperclip/issues/2021)这已合并但尚未正式发布,但应在Paperclip v 5.0.0
就像提到的Vitali Mogilevsky一样,你现在必须使用它:
# Gemfile
# ...
gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68'
发布Paperclip 5.0时,应包含AWS-SDK v2