Rails to_json.html_safe 未捕获的语法错误:意外的标识符
我在我的库存rails 3.1应用程序的projects#index.html.erb中有一个javascript部分,内容如下:
<script type="text/javascript" charset="utf-8">
var projects = <%= @projects.to_json.html_safe -%>
$(function () {
// some other code...
});
</script>
,Chrome的控制台现在会抱怨“未捕获的语法错误:意外的标识符”
但是,如果我删除“var项目”行后面的任何内容 像这样
<script type="text/javascript" charset="utf-8">
var projects = <%= @projects.to_json.html_safe -%>
</script>
一切都很好,当有人在 Chrome javascript 控制台中输入“projects”时,我确实得到了对象列表 [对象,对象,对象,...,对象]
我无法弄清楚这里的问题是什么,你能帮忙吗?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在语句末尾添加
;
分号try adding a
;
semicolon at the end of statement