I'm deploying a JRuby/Rails app packed up into "abc.war", and it is deployed with a Java app packed up into "def.war" in the same Tomcat instance.
I have a resource in my Rails application called "Blogs", with the following entry in routes.rb
resources :blogs
With this entry in routes.rb, I have helpers such as blogs_path() so I can use statements such as:
<%= link_to "Blogs", blogs_path %>
in my application view file, and hitting the generated link displays a list of blogs.
When this application runs standalone with the Webrick web server (JRuby 1.6.4, configured with Ruby 1.9, and Rails 3.0.10), it works fine, in that http://localhost:3000/blogs gets me a list of blogs when I hit that link). When I deploy the app to another base server URL such as, say, "http://funky-freddy-101.heroku.com", then I don't have to change the code with "blogs_path", because Rails automagically figures out the base URL and blogs_path() code takes that into account when building the actual URL generated by "blogs_path".
When deploying the app to JRuby/Tomcat in the file "abc.war", the base URL changes from http://localhost:3000" to "http://localhost:8081/abc". So typing "http://localhost:8081/abc/blogs" in the browser will give me a list of blogs, and "http://localhost:8081/blogs" gives me a 404 error. However, the problem is that although the base URL for the application includes the suffix of the WAR file name (i.e. "abc") Rails has not picked up on that and therefore still generates "http://localhost:8081/blogs" as the URL when blogs_path() is called. When I click on the link, it gives me the standard Tomcat 404 page.
Is there any simple way to get Rails to get the base URL suffixed with the reference "abc", the name of the WAR file, and generate URLs appropriately in a JRuby/Tomcat deployment? And because this application is running alongside def.war, I cannot make it the root app.
I found a similar question on stackoverflow.com. In the file /config.ru, I did the following:
map '/abc' do
run Abc::Application
end
I also had to make sure that I blew away the folder created by Tomcat to expand my WAR file before I deployed my new WAR.
Then my app just worked under the /abc URL scope, and it worked the same whether standalone or in a WAR file with Tomcat.
EDIT
One more thing you also add this to your config/environments/production.rb and config/environments/development.rb (if on production mode):
config.action_controller.asset_path = proc { |path| "/abc#{path}" }
otherwise when you call your helpers such as stylesheet_link_tag in your views, they will generate links without the "/abc".