Rails relative_url doesnt adjust links

▼魔方 西西 提交于 2019-12-05 10:04:15

I got it working by adjusting my reverse proxy and my rails config as follows. This is my corresponding apache file:

<VirtualHost *:80>
DocumentRoot /path/to/App/public
ProxyPass /App http://127.0.0.1:9292/App
ProxyPassReverse /App http://127.0.0.1:9292/App
</VirtualHost>

My config.ru looks like this:

require ::File.expand_path('../config/environment',  __FILE__)
map '/App' do
  run Rails.application
end

The mentioned environments variables are set in /config/environment.rb. I am not sure if they are still needed:

config.relative_url_root = "/App"
config.action_controller.relative_url_root = "/App"
ENV['RAILS_RELATIVE_URL_ROOT']  = "/App"
ENV['ROOT_URL']  = "/App"

In Rails 4.2, I had the same need and resolved modifying some configuration files. Routes.rb:

Rails.application.routes.draw do
  scope :mytm do
     ....
  end 
end 

This do not require any modification to the application.

Furthermore, you have to reconfigure the asset pipeline, in /config/initializers/assets.rb:

  Rails.application.config.assets.prefix = "/app/asset"
  ....

I'm not entirely sure if I understand what you're trying to do, but I think what you're describing is essentially namespacing all of your controllers under "/App" or something like that. This would be in your routes.rb file:

namespace "App" do

  # Put your resources here, as however you defined them before, e.g.:  
  resources :users, :decks, :cards, :revs, :sessions

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