【问题标题】:How to fix ActionText image attachment link resulting in error 404如何修复导致错误 404 的 ActionText 图像附件链接
【发布时间】:2020-05-21 15:40:31
【问题描述】:

我正在尝试在我自己的服务器上运行带有操作文本的页面的非常简单的 CMS。

在开发中一切正常。附件已上传,保存页面模型后即可查看。

切换到生产时,上传仍然有效,我可以在本地文件系统上看到文件,但查看页面显示图像标签损坏。

图片的链接看起来像

http://example.com/rails/active_storage/representations/SIGNED_ID/myimage.png

在我的本地制作中,链接是:

http://localhost:3000/rails/active_storage/disk/gsid/myimage.png?content_type=image%2Fpng&disposition=inline%3B+filename%3D%22myimage.png%22%3B+filename%2A%3DUTF-8%27%27myimage.png

我提供了一个secrete_key_base,将我的主机和所有东西列入白名单,以使应用程序在生产环境中运行。

我正在使用:

  • 独角兽
  • Nginx
  • Ruby 2.6.5
  • Rails 6.0.2.1

我的存储服务是“磁盘”,里面的所有文件和文件夹,包括RAILS_ROOT,都归运行应用程序的用户所有。

storage.yml:

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

routes.rb:

Rails.application.routes.draw do
  resources :pages, param: :seo_url, path: 'seite'

  get '/index', to: 'application#home', as: :home
  root to: 'application#home'
end

生产.rb:

  # Store uploaded files on the local file system (see config/storage.yml for options).
  config.active_storage.service = :local

有人知道为什么这不起作用吗?

【问题讨论】:

    标签: ruby-on-rails ruby actiontext


    【解决方案1】:

    我能够解决我的问题。我错误地配置了我的 Nginx。我将用于静态图像传递的错误配置 sn-p 粘贴到配置中。 我从 Nginx 配置中删除了这些行。现在一切正常。

    这实在是太尴尬了!

    【讨论】:

    • 你能分享你的 nginx 配置吗,因为我面临同样的问题,我不知道我错过了什么
    猜你喜欢
    • 2021-02-09
    • 2020-05-02
    • 1970-01-01
    • 2019-03-27
    • 2020-04-16
    • 2011-01-04
    • 2021-12-01
    • 1970-01-01
    • 2015-09-10
    相关资源
    最近更新 更多