views:

153

answers:

1

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"&gt; ) 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?

+1  A: 

override ActionView::Helpers::AssetTagHelper#compute_public_path private method with your own implementation. or do a smth like

module ActionView::Helpers::AssetTagHelper
    def compute_public_path_with_root_removed *args
        compute_public_path_without_root_removed(*args).sub(
            ActionController::Base.relative_url_root,
            ""
        )
    end
    alias_method_chain :compute_public_path, :root_removed
end

you can also make this override conditional, based on development/production environments, or anything

zed_0xff
It worked like a charm. I'm still not sure WHY it works, but thank you!
GSP