I have a rails application hosted on heroku with a url like exampleapp.herokuapp.com
. My company requires it to be served such that companydomain.com/exampleapp
will point to that heroku instance.
The configuration is as follows
In config/application.rb
:
config.action_controller.relative_url_root = "/exampleapp"
In config/environements/*.rb
config.assets.prefix = /exampleapp/assets
And for the routes, I have scoped them to an optional parameter like this
Rails.application.routes.draw do
scope '(:prefix)' do
# routes
end
end
And in application_controller.rb
def default_url_options
{prefix: 'exampleapp'}
end
This will make the application available in both prefixed and unprefixed url. For example: /login
and /exampleapp/login
will both work just fine and any other prefix will as well.
I guess it wouldn’t matter eitherway. But I want to know if this is a correct way to go about this?
Rails Version: 6.1.4
Ruby Version: 2.7.2