gpt4 book ai didi

ruby-on-rails - Rails 中的图像在生产中中断

转载 作者:行者123 更新时间:2023-11-29 14:37:53 24 4
gpt4 key购买 nike

在我将数据库从 sqlite3 更改为 postgres 之后,我使用 Cloud9 将我的应用程序部署到了 heroku。在那之后我的应用程序一直表现不佳。例如,生产中的图像在上传两三个小时后就中断了,这很糟糕。我还必须每隔几个小时启动一次 PostgreSQL,以便能够使用开发 sudo service postgresql start

这是我的database.yml:

default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: <%= ENV['USERNAME'] %>
password: <%= ENV['PASSWORD'] %>
host: <%= ENV['IP'] %>

development:
<<: *default
database: sample_app_development

test:
<<: *default
database: sample_app_test

production:
<<: *default
database: sample_app_production

我还听说它与 production.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 = true


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
end

仅供引用,在这个应用程序中注册的用户可以上传图片到应用程序,所以我不能只保存我想要的图片。

最佳答案

由于您不确定上传文件的路径,我认为您的问题出在这里。我使用 Heroku 的次数不多,但来自他们的 article :

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted. For example, this occurs any time a dyno is replaced due to application deployment and approximately once a day as part of normal dyno management.

因此,如果您的图像被上传到代码文件系统,它们对其他进程不可见,或者在替换 dyno 后它将被丢弃,因为当 heroku 替换 dyno 时,它只考虑在上次部署中部署的文件。并且没有上传的图片。

所以我建议你使用像 AWS S3 这样的 CDN。

关于ruby-on-rails - Rails 中的图像在生产中中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41607862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com