Rails 使用 puma,将 localhost:3000 更改为 localhost:3000/example

2024-04-09

我开发了一个 Rails 5 应用程序,可以很好地运行http://本地主机:3000/ http://localhost:3000/

现在,我需要该应用程序在 localhost:3000/example 中启动,并且该链接通过这个新主机(例如 localhost:3000/example/users/new)。我发现资产和 JavaScript 在 localhost:3000/example 中工作正常:

config.root_path = '/example'

但链接仍会重定向到旧链接(例如 localhost:3000/users/new)。

有人知道我该如何修复它吗?提前致谢


将整个路由配置包装在一个scope

#config/routes.rb

Rails.application.routes.draw do
   scope '/example' do
     #all the routes goes here
   end
end

您可以通过此更改资产交付路径

欲了解更多信息:https://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing https://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

#config/application.rb

config.action_controller.asset_host = "example.com"
config.assets.prefix = '/example'

https://guides.rubyonrails.org/v3.0.3/configuring.html#configuring-action-controller https://guides.rubyonrails.org/v3.0.3/configuring.html#configuring-action-controller

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails 使用 puma,将 localhost:3000 更改为 localhost:3000/example 的相关文章

随机推荐