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

Rails using puma, change localhost:3000 to localhost:3000/example

我开发了一个 rails 5 应用程序,在 http://localhost:3000/

中运行良好

现在,我需要此应用程序在 localhost:3000/example 中启动,并且该链接通过此新主机(例如 localhost:3000/example/users/new)。我有资产和 javascripts 在 localhost:3000/example with:

中工作正常
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

#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