我开发了一个 Rails 5 应用程序,可以在 http://localhost:3000/ 中正常运行
现在,我需要此应用程序在 localhost:3000/example 中启动,并且该链接通过此新主机(例如 localhost:3000/example/users/new)。我已经知道 Assets 和 JavaScript 在 localhost:3000/example 中工作正常:
config.root_path = '/example'
但链接仍重定向到旧链接(例如 localhost:3000/users/new)。
有人知道如何解决吗?提前致谢
最佳答案
将整个路由配置包装在范围
中
#config/routes.rb
Rails.application.routes.draw do
scope '/example' do
#all the routes goes here
end
end
您可以通过此更改 Assets 交付路径
了解更多信息: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
关于ruby-on-rails - Rails 使用 puma,更改 localhost :3000 to localhost:3000/example,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60073700/