bre*_*ter 10 ruby-on-rails coffeescript asset-pipeline
我正在使用Rails 3.2.14而没有问题......
我最近重命名application.js为application.js.coffee,现在收到JSON错误.
JSON::GeneratorError
only generation of JSON objects or arrays allowed
(in /.../app/assets/javascripts/application.js.coffee)
Run Code Online (Sandbox Code Playgroud)
即使我删除了所有内容,application.js.coffee我仍然会收到错误.
当我尝试直接查看它(http://localhost:3000/assets/application.js),它同样的问题:
throw Error("JSON::GeneratorError: only generation of JSON objects or arrays allowed\n (in /.../app/assets/javascripts/application.js.coffee)")
Run Code Online (Sandbox Code Playgroud)
我已针对任何潜在问题梳理了我的应用程序,但一切看起来非常标准.
我遇到了类似的问题(Rails 4资产管道抛出"只允许生成一代JSON对象或数组"),这与application.js无关.multi_json gem从1.7.8更新到1.7.9,并打破了我的应用程序.对cofeescript文件的任何更改都会导致"仅允许生成JSON对象或数组"错误.
我明确地将multi_json gem放在我的Gemfile中,修复为1.7.8版本.为我解决了问题.
小智 5
我的保存问题不在Rails项目中,而是使用sprockets的ruby项目.我还没有最终确定问题,但它似乎与execjs和使用的Javascript运行时有关.
你可以尝试添加
gem 'therubyracer'
到你的Gemfile.这安装了v8引擎,为我解决了这个问题.