ActionView::Template::Error (Unexpected character '#' deploying to Heroku - ruby-on-rails-3

For some reason, all of a sudden, I can't view my site via Heroku. I get this error
ActionView::Template::Error (Unexpected character '#' (line: 23168, col: 1, pos: 699588)
All research has pointed to my application.js having something going on in there, the file is large so would be unfair to put it on here, unless anyone needs to see it? Or is it something else?

So after some more research I had to compile the assets locally before deployment, which i have never had to do before, very strange
bundle exec rake assets:precompile

Related

Error message: NameError at /users/sign_in undefined local variable or method `require_no_authentication' for #<SessionsController:0x########>

I'm working on a RoR app with Devise. When I came in to work today and tried to start up my local dev environment, RoR failed when I tried to go to the sign in page:
NameError at /users/sign_in
undefined local variable or method `require_no_authentication' for #<SessionsController:0x########>
It looks like the error is not being raised within the code we wrote, but instead from deep within the Devise gem. I'm guessing that somehow, my dev machine isn't configured right.
Here are some things I've tried to fix the bug:
I ran rake db:migrate and rake db:terraform.
I ran bundle install.
I ran rvm gemset empty and bundle install to reinstall all of my gems.
None of these worked.
In addition, here are a couple more strange things about this error:
None of the other devs at my workplace are having the same error, even though they're on the same codebase.
After trying to figure out the error for a while, I switched to a branch that I haven't updated since before I started getting this bug. Even though it was working before the weekend, that branch now fails with the same error.
Does anybody know anything I could do to try to fix this error? Does it sound like some part of my local configuration is incorrectly set up?
In my project, I had added a file in app/controllers called devise_controller.rb. It looked like this:
class DeviseController < ApplicationController
# Asks Devise how much time is left until the current user is
# automatically logged out, without resetting the logout timer.
def time_until_logout
raise "let's inspect here"
end
end
When I deleted this file, the bug went away.
I filed a bug report about how adding a DeviseController caused RoR/Devise to blow up on Devise's repository: https://github.com/plataformatec/devise/issues/2520

How do I resolve Unexpected character '' error when precompiling assets in Rails?

I am trying to deploy my app for the first time and running into problems with the asset pipeline. When I run bundle exec rake assets:precompile I get the following error;
cool_app#ip-10-248-17-168:/rails_apps/cool_app/current$ bundle exec rake assets:precompile
/home/cool_app/.rvm/rubies/ruby-1.9.3-p327/bin/ruby /rails_apps/cool_app/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Unexpected character '' (line: 13934, col: 1, pos: 403510)
Error
at new JS_Parse_Error (<eval>:1720:22)
at js_error (<eval>:1728:15)
at parse_error (<eval>:1824:17)
at next_token (<eval>:2070:17)
at handle_slash (<eval>:2024:32)
at Object.next_token [as input] (<eval>:2067:39)
at next (<eval>:2175:37)
at Object.semicolon [as 1] (<eval>:2221:38)
at prog1 (<eval>:2770:28)
at simple_statement (<eval>:2362:35)
(in /rails_apps/cool_app/releases/20121128034720/app/assets/javascripts/application.js)
I presume that this means I have an illegal character (that's not rendering) somewhere in my maze of javascript (should have deployed earlier!) but telling me it's at column 1 on line 13934 doesn't seem to be particularly useful. How do I go about hunting this down? The error message is spectacularly unhelpful (and I notice a lot of other questions on this theme here too).
Edit -
I'm not sure of the significance, but if I run RAILS_ENV=development rake assets:precompile on my development machine, the task seems to execute without complaint. My Server is Ubuntu 12.04 and my dev machine in OSX 10.8. I don't know enough about Javascript runtimes to solve this myself right now (but I'm hunting).
Hokay,
My head hurts from the hours of bashing it against my keyboard but I solved my problem.
First, some reading around suggested that uglifier was the cause of my error. I set config.assets.compress = false in config/production.rb and sure enough I was able to precompile my assets.
I wasn't happy with this though as my Javascript file was 625kB and I really wanted it compressed, so I looked in the generated application.js file and found what line 13934, column 1 referred to. Turns out it was line 8, column 1 of the file jquery.caret.1.02.js, a small jQuery plugin I am using. This first line looks like so;
(function($,len,createRange,duplicate){
with a space in front of the line. I deleted that space (I suspect it is some incorrect non-printing unicode character but haven't bothered looking into it), set config.assets.compress = true, and tried again and no more error message! (and my Javascript is down to 159kB)
I hope that this helps someone one day.
another reason might be html-style comments in your js files.
this will produce
Unexpected character '<'
just to bring it out there, hope it saves someone some time and trouble
I've been bashing my head on this problem for a while as well. For me, the issue was in using the gem uglifier. When I removed uglifier and ran bundle exec rake assets:precompile again, I was successful.
It seems to a javascript compression issue, generally speaking. See what gems you are using to compress your JS

Heroku + Rails: weird error (Cedar Stack)

So I have deployed my app to heroku for testing for a couple of weeks and since yesterday I keep getting the following kind of errors in the heroku logs:
Started GET "/user/shipping_address" for xx.xxx.xxx at 2012-02-09 15:46:37 +0000
NameError (undefined local variable or method `sign_up_path' for #<UsersController:0x000000036210a8>):
app/controllers/application_controller.rb:57:in `require_user'
Another one:
Started POST "/purchase/search" for xx.xxx.xxx at 2012-02-09 15:31:30 +0000
NameError (undefined local variable or method `sign_up_path' for #<PurchasesController:0x000000051a3d08>):
app/controllers/application_controller.rb:57:in `require_user'
I also keep getting (really) weird javascript errors in firebug, like "object_id" missing, where object_id should never be used at that point in code.
It works without any flaws in the local environment on development/production and also all the time before on my heroku app.
Any hints greatly appreciated. This error is really killing me.
Best, Phil
(Cedar-Stack, Rails 3.0, authlogic)
Ok I updated authlogic to the newest version 3.1.0 (think it was on 3.0.3) and everything works for now.

How to solve the following rails 3 error: ArgumentError (Syck is not missing constant BadAlias!)?

I've got a strange error with a rails 3.0.3 application running on ruby 1.9.2, as a matter a fact it doesn't run yet, beacause I get the following error:
ArgumentError (Syck is not missing constant BadAlias!):
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (14.4ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (19.4ms)
Is because of the ruby version? Or how can I solve this?
-- later edit:
On ruby 1.8.7 EE, I have no such error.
After searching and searching the internet, I started to look at all my YAML in my app, and I validate each file using: http://yaml-online-parser.appspot.com/, and I've got errors like:
while parsing a flow node
expected the node content, but found ':'
in "<unicode string>", line 147, column 13:
order: [:day, :month, :year]
Therefore everything was because the yaml errors. The problem is with unicode, in seems that its different on ruby 1.9.2 than in 1.8.7.

heroku rake require 'rake/dsl_definition' fix not working + breaking local rake

I'm having the same heroku rake issues described (and from what I can tell solved) in this question.
When I try the fix (include require 'rake/dsl_definition' above require 'rake') I get the same
'uninitialized constant Rake::DSL'
error from heroku + I get the error
'no such file to load -- rake/dsl_definition'
from my local rake.
Without incorporating the fix (using the standard rakefile) I can use rake on my local setup with no errors (with the same heroku error)
I'm using rake version 0.8.7 (though I get the same results using 0.9.2) and Rails 3.0.9. I've gone through the suggestions in the previous question but from what I can tell the problem isn't with my Gemfile. Has anyone else had this problem? Has anyone else solved their heroku rake problem using a different solution? Or can anyone explain/suggest how I'm going about this incorrectly?
Thank you for your help.
Try adding require 'rake/dsl_definition' on top of Rakefile.
Not enough for me. I was getting the no such file to load -- rake/dsl_definition error even adding the require 'rake/dsl_definition' line in the "Rakefile" file
I had all gems version OK and only 0.8.7 rake version but I had to create a "Gemfile" in the redmine root path with the next content:
gem "rake", "0.8.7"
And delete the require 'rake/dsl_definition' line added previously in Rakefile
Hope be usefull for someone