Changing the base URL for Rails 3 development

后端 未结 3 1025
别跟我提以往
别跟我提以往 2020-12-01 04:50

I know I\'m going to deploy to an environment with my application running with a base URL which looks like this:

http://someserver/mydepartment/myapp
         


        
相关标签:
3条回答
  • 2020-12-01 05:19

    Add the below line to the end of config/environment.rb

    ActionController::Base.relative_url_root = "/mydepartment"
    
    0 讨论(0)
  • 2020-12-01 05:22

    You can try mapping your rails app rack config to a different base_uri. All you need to do is wrap the existing 'run' command in a map block

    try doing this in your rails 'config.ru' file:

    map '/mydepartment' do
        run Myapp::Application
    end
    

    Now when you 'rails server' the app should be at localhost:3000/mydepartment . Not sure if this will give you the desired outcome, but worth a try.

    0 讨论(0)
  • 2020-12-01 05:40

    Here’s how you can deploy a Rails 3.1 app to a subdirectory in Apache, replacing config.action_controller.relative_url_root which no longer exists.

    In config/routes.rb:

    scope 'my_subdir' do
      # all resources and routes go here
    end
    

    In your Apache configuration file:

    Alias /my_subdir /var/www/my_subdir/public
    <Location /my_subdir>
      SetEnv RAILS_RELATIVE_URL_ROOT "/my_subdir"
      PassengerAppRoot /var/www/my_subdir
    </Location>
    

    And it should work, including automatically pointing all your assets to /my_subdir.

    0 讨论(0)
提交回复
热议问题