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

时间:2020-02-05 10:26:58

标签: ruby-on-rails ruby-on-rails-5 puma

我已经开发了Rails 5应用程序,在http://localhost:3000/

中可以正常工作

现在,我需要该应用程序从localhost:3000 / example启动,并且链接通过此新主机(例如localhost:3000 / example / users / new)。我已经知道资产和javascript在localhost:3000 / example中运行良好,

config.root_path = '/example'

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

谁知道我该如何解决?预先感谢

1 个答案:

答案 0 :(得分:2)

将整个路由配置包装在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