windows – rake资产:预编译不起作用(rails 3.1.1)

前端之家收集整理的这篇文章主要介绍了windows – rake资产:预编译不起作用(rails 3.1.1)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在部署到heroku但我看到没有提供css文件(它们也无法在heroku上找到).

我读到我需要做rake资产:首先在本地预编译然后当我这样做时,我得到:

C:\project>bundle exec rake assets:precompile --trace

** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
undefined: Unexpected token: operator (<)
  (in C:/project/app/assets/javascripts/application.js)

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

我在application.js中什么也没有,所以我不明白错误在哪里..

application.js是

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here,but if you do,it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

谢谢

更新

如果删除.js.erb文件,我会收到以下错误

C:\project>bundle exec rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
706: unexpected token at 'C:\Users\me\AppData\Local\Temp\execjs20111021-6448-ei2nm3.js(2,3) Microsoft JScript runtime error: Out of memory

'
  (in C:/project/app/assets/javascripts/application.js)

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

仍然有erb css和js文件没有编译的问题…

这似乎没有结束..
谢谢

我认为它是由外部javascript文件引起的,这个文件没有良好的代码格式.例如
function say_hi(){
  // NOTICE that there's no semi-colon there!
  name = "Jim"
  alert("hi" + name )
}

在预编译下,你的代码将放入1行,并且因为没有必要的分号,你生成的js文件可能包含错误,比如

"undefined: Unexpected token: operator (<)"

或者其他的东西.

所以,我的建议是:

>如果js文件代码格式不正确,请不要压缩js文件,方法是在配置文件中设置“config.assets.compress = false”,然后按@ Mike的回答.>尽可能使用coffeescript,它将帮助您生成格式良好的代码. (我不是coffeescript大师,所以如果我错了请纠正我)

猜你在找的Windows相关文章