在rails中更改默认样式表目录

bun*_*ich 5 css ruby-on-rails stylesheet

有人知道在rails 3中将默认样式表目录/ public/stylesheets更改为/ public/css吗?

我发现了一个名为的变量 config.stylesheets_dir = '/css'

但这并没有奏效.

我知道我能做到,<%= stylesheet_link_tag '/css/mystyle.css' %>但我很好奇是否有更好的方法.

ger*_*tas 3

Javascript 和样式表路径在 Rails 3 中并未完全解硬编码。要覆盖这些路径,您需要猴子修补(及其所有后果)私有方法:

module ActionView::Helpers::AssetTagHelper
    private
      def compute_stylesheet_paths(*args)
          expand_stylesheet_sources(*args).collect { |source| compute_public_path(source, 'stylesheets', 'css', false) }
      end
end
Run Code Online (Sandbox Code Playgroud)

如果你使用它的话,还有这个:

  def stylesheet_path(source)
    compute_public_path(source, 'stylesheets', 'css')
  end
Run Code Online (Sandbox Code Playgroud)