0

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

我知道这可能是因为模块混入了,那么我该如何解决呢?

4

1 回答 1

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

我个人不会走这条路,但如果你需要它应该对你有用:)

于 2009-05-23T18:12:16.677 回答