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

浪子不回头ぞ 提交于 2020-05-15 20:40:22

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/60073700/rails-using-puma-change-localhost3000-to-localhost3000-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!