rake assets:precompile doesn't work (rails 3.1.1)
I've been struggling with this trying to deploy to a staging server. The solution that works for me is to make sure you have the following in your config/environments/[your_environment].rb
file:
config.assets.compress = false
By default, the compressors aren't available in environment other than production, which is why the precompile was failing.
I have the same issue here! In my case, what causes this issue is that, I add a new JS file to javascript folder, and I got an undefined: Unexpected token: operator (<)
error while I tried to run precompile command. So I look into the new js file and found there is a HTML style comment <!-- -->
in that file. I remove it and life is good now!
So try to find out is there any HTML style comment <!-- -->
in your js file and just remove those comments. This is especially true when some JS code is copied from html file!
I think it is caused by an external javascript file which is not well-code-formatted. e.g.
function say_hi(){ // NOTICE that there's no semi-colon there! name = "Jim" alert("hi" + name )}
when under the precompile, your code would put in 1 line, and since there's no necessary semicolon, your generated js file probably contains errors, like
"undefined: Unexpected token: operator (<)"
or something.
so, my suggestion is:
don't compress the js file if it's not well code-formatted, by setting "config.assets.compress = false" in your config file, following @Mike's answer.
use coffeescript as possible, it will help you generate very well formatted code. ( I am not a coffeescript guru, so please correct me if I am wrong )