cabcookie
cabcookie

Reputation: 51

token_error on heroku when I try to load Google API

I am using winston/google_visualr to create nice graphs to visualize statistics in my rails application.
It works fine on my locale system, but if I push it to heroku I get something like a token_error. The result is, that it shows only the Heroku page

We're sorry, but something went wrong.

My head section of application.html.erb looks like this

<head>
    <title><%= full_title(yield(:title)) %></title>
    <script src='http://www.google.com/jsapi'></script>
    <%= stylesheet_link_tag    "application", :media => "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>
</head>  

This is the heroku log:

ActionView::Template::Error (Unexpected token name, expected punc (line: 13588, col: 3, pos: 384041)
    at expect (/tmp/execjs20121119-2-qx6eku.js:977:40)
Error
    at js_error (/tmp/execjs20121119-2-qx6eku.js:505:15)
    at new JS_Parse_Error (/tmp/execjs20121119-2-qx6eku.js:497:22)
    at token_error (/tmp/execjs20121119-2-qx6eku.js:961:17)
    at expect_token (/tmp/execjs20121119-2-qx6eku.js:974:17)
    at object_ (/tmp/execjs20121119-2-qx6eku.js:1365:56)
    at /tmp/execjs20121119-2-qx6eku.js:1326:51
Completed 500 Internal Server Error in 4980ms
    at croak (/tmp/execjs20121119-2-qx6eku.js:954:17)
    at maybe_unary (/tmp/execjs20121119-2-qx6eku.js:1425:27)
    at expr_ops (/tmp/execjs20121119-2-qx6eku.js:1452:32)
   (in /app/app/assets/javascripts/application.js)):
    6:    <%= stylesheet_link_tag    "application", :media => "all" %>
    7:    <%= javascript_include_tag "application" %>
    8:    <%= csrf_meta_tags %>
    9:    <%= render 'layouts/shim' %>
    4:    <title><%= full_title(yield(:title)) %></title>
    5:    <script src='http://www.google.com/jsapi'></script>
  app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb__1437494530852335371_34567960'

It looks like that the external script reference may be the reason. Do you have any idea how to implement this?
The demo implementation of the author of the googlevisualr rails extension on heroku works fine. Is there any configuration settings in heroku I need to consider? Thanks for your help.

Upvotes: 1

Views: 316

Answers (1)

cabcookie
cabcookie

Reputation: 51

It took me a lot of tries but I found the issue. The error happens if one of the included JS' has syntax errors, i.e. a missing semicolon. In my Gemfile I didn't add version numbers to my gem '...'. I was using the gem 'bootstrap-datepicker-rails' in version '0.6.21' for my development environment. If you push to heroku all your gems will be installed again, with the newest available version. Since version 0.6.28 is the actual version it was installed on heroku. It may have a syntax error and it caused the above issue. So, it had nothing to do with the line

<script src='http://www.google.com/jsapi'></script>

I just corrected the line in my gemfile to the following and all was working then:

gem 'bootstrap-datepicker-rails', '0.6.21'

Upvotes: 1

Related Questions