2010-05-28 24 views
0

在我们的Intranet环境中,我们有一个法令,应该从Apache根提供公共资产(样式表,图像等),而Rails应用程序则从“子目录”(代理到Mongrel集群)运行。换句话说:如何使ActionController :: Base.asset_host和Base.relative_url_root独立?

<%= 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/" /> 

我想要做的就是定义在我的配置是这样的资产相对URL:

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

但是当我这样做时,relative_url_root价值被附加到asset_host值。 (例如<link href="http://1.1.1.1/myapp/stylesheets/common.css">)有没有办法阻止它?而且,更重要的是,如何将Rails应用程序部署到这样的环境中,是否有最佳做法?

(顺便说一句,我不想​​因为开发环境不匹配,测试和生产环境根本就很难码我的素材资源路径。)

环境:
的Rails 2.3.4
红宝石1.8。 7
RedHat Linux 5.4?

回答

2

重写ActionView :: Helpers :: AssetTagHelper#compute_public_path具有您自己的实现的私有方法。 或不喜欢

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 

一个不便还可以使此覆盖条件的基础上,开发/生产环境,或任何

+0

它的工作就像一个魅力。我仍然不确定它为什么有效,但谢谢! – GSP 2010-06-01 12:44:22