【问题标题】:Not able to post new content after putting AWS S3 on my Heroku Ruby on Rails App将 AWS S3 放在我的 Heroku Ruby on Rails 应用程序上后无法发布新内容
【发布时间】:2016-07-27 02:01:32
【问题描述】:

我是 Ruby on Rails 的新手,为了练习,我决定构建 Dribble 类型的应用程序(Mackenszie Child youtube 系列)。我能够构建它并将其成功部署到 Heroku 和我的本地环境中。但是,我还想练习将我的图像放在 Amazon Web Services S3 上 - 这就是问题开始的时候。我可以部署到 heroku,但是当我想开始新帖子时,我会收到错误提示“我们很抱歉,但出了点问题。”我在我的 heroku 应用程序链接、我的 github 存储库、我的 heroku 日志、我的生产 rb 文件和我的 postrb(模型)下面列出了 - [我觉得那是我可能会出错的地方]。非常感谢你们帮助我。

我尝试过但没有成功但让我接近的类似 Stackoverflow 方法:

1 - 非常接近)Rails 4: Heroku + Paperclip + s3 not working in production

2) Paperclip Amazon S3 setup with Heroku


Github 存储库:https://github.com/OmarZV/muse

我的 Heroku 应用网站:https://intense-shelf-74152.herokuapp.com/

Heroku 最新日志:

2016-07-27T14:58:19.093639+00:00 heroku[api]: Release v16 created by oek203@nyu.edu
2016-07-27T14:58:19.093594+00:00 heroku[api]: Attach PAPERTRAIL (@ref:papertrail-spherical-45365) by oek203@nyu.edu
2016-07-27T14:58:26.753023+00:00 app[web.1]: [2016-07-27 14:58:26] INFO  WEBrick 1.3.1
2016-07-27T14:58:26.753289+00:00 app[web.1]: [2016-07-27 14:58:26] INFO  WEBrick::HTTPServer#start: pid=3 port=12517
2016-07-27T14:58:26.753041+00:00 app[web.1]: [2016-07-27 14:58:26] INFO  ruby 2.2.4 (2015-12-16) [x86_64-linux]
2016-07-27T14:58:27.146586+00:00 heroku[web.1]: State changed from starting to up
2016-07-27T14:59:12.660585+00:00 heroku[router]: at=info method=GET path="/" host=intense-shelf-74152.herokuapp.com request_id=b5bc6545-aa59-4c48-93d1-0e6d2e1b7f8f fwd="66.150.113.6" dyno=web.1 connect=0ms service=124ms status=200 bytes=2037
2016-07-27T14:59:14.551411+00:00 heroku[router]: at=info method=GET path="/posts/new" host=intense-shelf-74152.herokuapp.com request_id=cd6d6784-b3ee-42a7-abad-f08380cd8be2 fwd="66.150.113.6" dyno=web.1 connect=3ms service=38ms status=500 bytes=1754
2016-07-27T15:03:08.539026+00:00 heroku[router]: at=info method=GET path="/" host=intense-shelf-74152.herokuapp.com request_id=384f66f6-9bb0-4805-a396-5dcddd41685b fwd="66.150.113.6" dyno=web.1 connect=0ms service=11ms status=200 bytes=2037
2016-07-27T15:03:10.358959+00:00 heroku[router]: at=info method=GET path="/posts/new" host=intense-shelf-74152.herokuapp.com request_id=84d96bfe-fa4f-40a0-9eb8-28b40dc83aba fwd="66.150.113.6" dyno=web.1 connect=1ms service=16ms status=500 bytes=1754

生产 RB:

Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
#Setting up paperclip for AWS
  config.paperclip_defaults = {
  storage: :s3,
  s3_credentials: {
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('AWS_REGION'),
  }
}
end

Post.rb:

class Post < ActiveRecord::Base
  acts_as_votable
  belongs_to :user
  has_many :comments
  has_attached_file :image, styles: { medium: "700x500#", small: "350x250>" }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
end

【问题讨论】:

  • 什么是错误..你能用papertrail检查吗...?发布它
  • 希望您已使用 aws-sdk gem 正确配置 AWS,并使用 s3.yml 之类的东西进行身份验证所需的凭证,它必须保存您的开发/生产 access_key_id、bucket 和 secret-access-key...?
  • Milind,感谢您的回复。我已经更新了问题以显示我的产品 rb - 您会注意到我完全遵循了 heroku 指南 - devcenter.heroku.com/articles/paperclip-s3。 > 该指南从未提及 s3.yml
  • Milind,我也刚刚添加了我的 heroku 日志,错误是用户无法发布新内容,因为他们无法访问 > intense-shelf-74152.herokuapp.com/posts/new 出现一条消息说“我们正在抱歉,出了点问题。如果您是应用所有者,请查看日志以获取更多信息"

标签: ruby-on-rails amazon-web-services heroku amazon-s3


【解决方案1】:

在不断研究之后才弄清楚 - 问题与端点、存储桶名称和我的主机名有关。这以以下方式搞砸了事情。

为了添加图像,我必须这样做: 1.heroku 配置:取消设置 AWS_BUCKET 2.heroku 配置:设置 AWS_BUCKET = kamari1.s3.us-east-1.amazonaws.com 3.heroku 配置:未设置 4. heroku 配置:设置 AWS_BUCKET = kamari1

我通过查看 aws s3 控制台并配置我的端点来解决这个问题,以便正确引导它们。之后确保运行以下命令“heroku pg:reset DATABASE”,你将成为一个快乐的露营者:)

AWS_BUCKET:kamari1.s3.us-east-1.amazonaws.com

S3_HOST_NAME:s3.us-east-1.amazonaws.com

http://i.stack.imgur.com/dvmxL.png

【讨论】:

    猜你喜欢
    • 2011-04-29
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 2018-06-10
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多