How to make ActionController::Base.asset_host and Base.relative_url_root independent?

Posted by GSP on Stack Overflow See other posts from Stack Overflow or by GSP
Published on 2010-05-28T18:23:46Z Indexed on 2010/05/28 18:32 UTC
Read the original article Hit count: 251

Filed under:

In our Intranet environment we have a decree that common assets (stylesheets, images, etc) should be fed from Apache root while Rails apps runs from from a "sub directory" (a proxy to a Mongrel cluster). In other words:

<%= stylesheet_tag '/common' %> 
# <link href="http://1.1.1.1/stylesheets/common.css" />

<%= link_to 'Home', :controller=>'home', :action=>'index' %> 
# <a href="http://1.1.1.1/myapp/" />

What I would like to do is define the assets and relative url in my configuration like this:

ActionController::Base.asset_host=http://1.1.1.1
ActionController::Base.relative_url_root=/myapp

But when I do this, the relative_url_root value gets appended to the asset_host value. (e.g. <link href="http://1.1.1.1/myapp/stylesheets/common.css"> ) Is there a way to stop this? And, more importantly, is there a best practice for how to deploy a rails app to an environment like this?

(BTW, I don't want to simply hard code my asset paths since the development environment does not match the test and production environments.)

Environment:
Rails 2.3.4
Ruby 1.8.7
RedHat Linux 5.4?

© Stack Overflow or respective owner

Related posts about ruby-on-rails