Nick Ginanto
Nick Ginanto

Reputation: 32130

JSON::GeneratorError in a .js.erb file

I don't understand what I'm doing wrong..

I am attempting to catch a 401 unauthorized and inserting a div with a message before the submit button using

$(function() {
  return $("a").ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
    if (jqXHR.status === 401) {
      $(".submit").before(<%=j content_tag :div, "Does not compute" %> );
    }
  });
});

the name of the file is home.js.erb

even before the page loads I get

JSON::GeneratorError in Pages#home

Showing H:/project/app/views/layouts/application.html.erb where line #6 raised:

only generation of JSON objects or arrays allowed
  (in H:/project/app/assets/javascripts/home.js.erb) 

line #6 refers to

5:   <%= stylesheet_link_tag    "application.css", :media => "all" %>
6:   <%= javascript_include_tag "application" %>

obviously something is wrong.. but what?

Upvotes: 0

Views: 271

Answers (2)

lingceng
lingceng

Reputation: 2425

May be a bug of execjs that time:

https://github.com/sstephenson/execjs/issues/129

Just update your execjs version to fix.

Upvotes: 0

Nick Ginanto
Nick Ginanto

Reputation: 32130

solved by removing the j..

which I don't understand... shouldn't j make it so I can put it in javascript?

Upvotes: 1

Related Questions