Rails 使用 puma,将 localhost:3000 改为 localhost:3000/example [英] Rails using puma, change localhost:3000 to localhost:3000/example

查看:93
本文介绍了Rails 使用 puma,将 localhost:3000 改为 localhost:3000/example的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个在 http://localhost:3000/

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

config.root_path = '/example'

但链接仍然重定向到旧的(例如,localhost:3000/users/new).

有人知道我该如何解决吗?提前致谢

解决方案

将整个路由配置包装在 scope

#config/routes.rbRails.application.routes.draw 做范围 '/example' 做#所有的路线都在这里结尾结尾

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

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

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

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

I have developed a rails 5 application that works fine in http://localhost:3000/

Now, I need that this application starts in localhost:3000/example, and that links goes through this new host, (localhost:3000/example/users/new for example). I have got that assets and javascripts works fine in localhost:3000/example with:

config.root_path = '/example'

but links still redirects to the old one (for example, localhost:3000/users/new).

Anyone know how can I fix it? Thanks in advance

解决方案

wrap your entire routes configurations in a scope

#config/routes.rb

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

you can change how assets delivery path with this

for more info : 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

这篇关于Rails 使用 puma,将 localhost:3000 改为 localhost:3000/example的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆