gpt4 book ai didi

ruby-on-rails - Rails 使用 puma,更改 localhost :3000 to localhost:3000/example

转载 作者:行者123 更新时间:2023-12-04 10:37:57 24 4
gpt4 key购买 nike

我开发了一个在 http://localhost:3000/ 中运行良好的 rails 5 应用程序

现在,我需要这个应用程序在 localhost:3000/example 中启动,并且该链接通过这个新主机,(例如 localhost:3000/example/users/new)。我有 Assets 和 javascripts 在 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

您可以通过此更改 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/

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