Rails 3资产管道:如何防止为每个人加载一些资产文件(例如,浏览器特定的)

时间:2012-03-16 13:20:09

标签: ruby-on-rails-3 asset-pipeline rails-3.1

我想将'excanvas.min.js'文件仅提供给Internet Explorer,提供给其他浏览器

所以我在我的application.html.erb

中做了
<!--[if lt IE 9]>
<%= javascript_include_tag 'excanvas.min'
# Excanvas for use of Canvas in IE up to version 8
%>
<![endif]-->
<%= javascript_include_tag 'application' %>

但我收到以下错误(正在制作中):

Completed 500 Internal Server Error in 3ms

ActionView::Template::Error (excanvas.min.js isn't precompiled)

强制Rails使用

预编译文件时也会发生错误
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
config.assets.precompile += %W(excanvas.min.js,other_file.css,even_anotherfile.js)
'config / production.rb'中的

。我做错了什么?

我可以做一个

//= require excanvas.min
application.js中的

。但那将包括每个浏览器的文件......

信息:我使用Rails 3.0-Application进行了更新。

2 个答案:

答案 0 :(得分:3)

问题出在以下一行

config.assets.precompile += %W(excanvas.min.js,other_file.css,even_anotherfile.js)

%W是创建数组的快捷方式,项目需要用空格分隔。在您的情况下,您将字符串excanvas.min.js,other_file.css,even_anotherfile.js添加到预编译列表。

所以只需按如下方式替换该行:

config.assets.precompile += %W(excanvas.min.js other_file.css even_anotherfile.js)

答案 1 :(得分:1)

尝试添加&lt;%#%&gt;对于线和。 我认为它们会显示为评论。

OR

你可以这样做js.judge浏览器用js并加载相应的css文件