json, rails, parse error in javascript

前端 未结 3 749
不思量自难忘°
不思量自难忘° 2021-01-17 02:28

I need to get a ruby array in to a javascript array and I\'m getting a parse error.

var characters = <%= @poop.to_json %>;

That is how

3条回答
  •  太阳男子
    2021-01-17 02:53

    Ideally, we need more information to properly answer, but I'm going to guess some stuff to help you...

    Assumption #1: You are using erb syntax (those "<%=" and "%>") in a .js file. These aren't parsed by Rails into anything meaningful.

    What you want to do, is use inline JS in your template or view. Javascript generation from other languages can be tricky though, use with caution.

提交回复
热议问题