2009-05-23 81 views
0

我一直试图覆盖Rails的stylesheet_path帮手,但我还没找到方法。我不能只打开ActionView::Helpers::AssetTagHelper模块并在那里覆盖它,因为Rails不会采用我的新方法。Rails:如何覆盖stylesheet_path

我知道这可能是因为模块混入了,所以我该如何解决这个问题?

回答

1

你是否这样做,使stylesheet_link_tag会导致不同于正常的东西?如果是这样,只是覆盖在助手:)

或者,如果你真的想覆盖stylesheet_path,您还需要重新定义的别名,如,奇怪的是,它只能通过它的别名访问(用Rails 2.3。 2)。例如,我把这个environment.rb和它的工作:

module ActionView 
    module Helpers 
    module AssetTagHelper 
     def stylesheet_path(source) 
     "x" 
     end 
     alias_method :path_to_stylesheet, :stylesheet_path 
    end 
    end 
end 

我个人不会走这条路线,但它应该为你工作,如果你需要它:)