1

I have in my stock rails 3.1 app's projects#index.html.erb a javascript section to reads like this:

<script type="text/javascript" charset="utf-8">
var projects = <%= @projects.to_json.html_safe -%>
  $(function () {
    // some other code...
  });
</script>

However, Chrome's console complains that "Uncaught SyntaxError: Unexpected identifier"

now, if I remove anything that follows the "var projects" line like this

<script type="text/javascript" charset="utf-8">
var projects = <%= @projects.to_json.html_safe -%>
</script>

everything is fine and when one typed "projects" in the Chrome javascript console, I do get the list of objects [ object, object, object, ..., object ]

I cannot work out what the issue is here, can you help?

Thanks!

Nik So
  • 16,683
  • 21
  • 74
  • 108
  • try adding a `;` semicolon at the end of statement – rubish Jul 22 '11 at 03:05
  • I swear, I did try that, and that time didn't work. And now it works :) Well, that's life.. Thanks!! Oh, how do i choose you as the answer? – Nik So Jul 22 '11 at 03:15

1 Answers1

4

try adding a ; semicolon at the end of statement

rubish
  • 10,887
  • 3
  • 43
  • 57