gpt4 book ai didi

ruby-on-rails - Rails 6 relative_url_root 不适用于子目录中的部署

转载 作者:行者123 更新时间:2023-12-03 20:50:19 25 4
gpt4 key购买 nike

我正在将 Rails 6 应用程序部署到子文件夹 (/dictionnaire-app) 中。我设置了config.relative_url_root = "/dictionnaire-app"在 application.rb 中,还根据 the documentation 添加了 ENV 变量.
但是,如果 Assets 正确呈现,则会生成带有 link_to 的链接。方法不会相应更新。
我阅读了许多与此问题相关的问题,并尝试在我的 routes.rb 文件中创建一个范围,如下 these instructions .

Rails.application.routes.draw do
mount ForestLiana::Engine => '/forest'
root to: "home#index"

scope 'dictionnaire-app' do
resources :words, path: "definition", param: :slug

post '/search', to: 'words#search'
get '/recherche', to: 'words#search_page'
get '/:letter', to: 'words#alphabet_page', param: :letter, as: "alphabetic_page"
end

end
不幸的是,该应用程序抛出一个错误,指出此 URL 的页面不存在: https://www.lalanguefrancaise.com/dictionnaire-app/definition/rameal
但是,此 URL 有效: https://www.lalanguefrancaise.com/dictionnaire-app/dictionnaire-app/definition/rameal
知道如何解决这个问题并在/dictionnaire-app/* 上呈现应用程序吗?
谢谢。
编辑:这个问题似乎来自 Rails ( see here )。有什么办法可以找到解决办法吗?

最佳答案

我以前没有尝试过,但我可以想象这样的事情可能会奏效:

# config/routes.rb
if Rails.application.config.relative_url_root == "/dictionnaire-app"
extend DictionaryRoutes
else
scope 'dictionnaire-app' do
extend DictionaryRoutes
end
# config/routes/dictionary_routes.rb
module DictionaryRoutes
def self.extended(router)
router.instance_exec do
resources :words, path: "definition", param: :slug

post '/search', to: 'words#search'
get '/recherche', to: 'words#search_page'
get '/:letter', to: 'words#alphabet_page', param: :letter, as: "alphabetic_page"
end
end
end
通常,您不希望在路由中使用 if-else,但在这种情况下,您实际上是在为应用动态定义路由是否存在。可能需要更多自定义才能使其正常工作。假设您试图允许 /search因为你的路线不是 /dictionnaire-app/search (或者是导致问题的原因)。
虽然看到尚未发布,但尚不清楚这是否会是那么简单的修复。

关于ruby-on-rails - Rails 6 relative_url_root 不适用于子目录中的部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63228898/

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