Ruby on rails 更改rails中的默认样式表目录
有人知道在rails 3中将默认的样式表目录/public/stylesheets更改为/public/css吗 我发现了一个变量,名为Ruby on rails 更改rails中的默认样式表目录,ruby-on-rails,css,stylesheet,Ruby On Rails,Css,Stylesheet,有人知道在rails 3中将默认的样式表目录/public/stylesheets更改为/public/css吗 我发现了一个变量,名为 config.stylesheets\u dir='/css' 但这不起作用 我知道我可以做,但我很好奇是否有更好的方法。Javascript和样式表路径在Rails 3中没有完全编码。 要覆盖这些路径,您需要使用monkey-patch(所有结果) 私人方法: module ActionView::Helpers::AssetTagHelper pr
config.stylesheets\u dir='/css'
但这不起作用
我知道我可以做
,但我很好奇是否有更好的方法。Javascript和样式表路径在Rails 3中没有完全编码。
要覆盖这些路径,您需要使用monkey-patch(所有结果)
私人方法:
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
另外,如果您使用它,请使用:
def stylesheet_path(source)
compute_public_path(source, 'stylesheets', 'css')
end
或者,下面是我正在做的。我创建了一个包装器
asset\u标记
,可以这样使用:
<%= asset_tag 'mystyle', :css %>
<%= asset_tag 'mycode', :js %>
通过这种方式,您可以以任何方式更改资产路径,并且它将始终是向前兼容的。我不知道为什么会被否决。这是一个更明确的解决方案,而且不太老套。
module ApplicationHelper
# here is where you define your paths
# in this case, paths will be '/css/mystyle.css' and '/js/mycode.js'
def asset_path(asset, type)
return "/css/#{asset}.css" if type == :css
return "/js/#{asset}.js" if type == :js
end
def asset_tag(asset, type)
return stylesheet_link_tag asset_path(asset, type) if type == :css
return javascript_include_tag asset_path(asset, type) if type == :js
end
end