我正在部署到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 .
谢谢
更新
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大师,所以如果我错了请纠正我)