JSON :: GeneratorError - 应用程序抛出"只生成JSON对象或数组的生成"错误

时间:2014-07-29 17:05:08

标签: ruby-on-rails ruby json

我正在使用Ruby on Rails 4.1为我的示例项目创建一个票务预订应用程序。三个是三个模型 - 活动,门票和预订。活动有很多门票和预订。门票有很多预订,属于活动。预订属于活动和门票。

这里是gemfile:

source 'http://code.stripe.com'
source 'https://rubygems.org'

ruby '2.1.2'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'


# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
gem 'execjs'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'figaro'
gem 'stripe'
gem 'tinymce-rails'
gem 'geocoder'
gem 'gmaps4rails'
gem 'heroku'
gem 'iconv'
gem 'multi_json', '1.10.1'
gem 'therubyracer'

group :development do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
  gem 'thin'
  gem 'rails_12factor'
end

# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

我使用tinymce-rails gem在新页面和编辑页面中创建一个WYSIWYG编辑器。宝石需要使用<%= tinymce%>在所有相应的视图文件中。该应用程序运行正常,我能够在本地使用编辑器,没有任何问题。

新的活动页面如下:

<h2>Create an Event</h2>
<%= tinymce_assets %>
<%= form_for (@event) do |f| %>
  <% if @event.errors.any? %>
      <div id="error_explanation">
        <h2><%= pluralize(@event.errors.count, "error") %> prohibited
          this event from being saved:</h2>
        <ul>
        <% @event.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
        </ul>
      </div>
  <% end %>
    <div class="form-group">
      <%= f.label :name %>
      <%= f.text_field :name, class: "form-control" %>
    </div>
    <div class="form-group">
      <%= f.label :about %>
      <%= f.text_area :about, class: "tinymce" %>
    </div>
    <div class="dropdown">
      <%= f.label :time_zone %>
      <%= f.time_zone_select :time_zone, nil, {}, {class: "btn btn-default dropdown-toggle"} %>
    </div>
    <div class="form-group">
      <%= f.label :start_date %>
      <%= f.datetime_select :start_date %>
    </div>
    <div class="form-group">
      <%= f.label :end_date %>
      <%= f.datetime_select :end_date %>
    </div>
    <div class="form-group">
      <%= f.label :location %>
      <%= f.text_field :location, class: "form-control" %>
    </div>
    <div class="form-group">
      <%= f.label :contact_info %>
      <%= f.text_area :contact_info, class: "form-control" %>
    </div>
      <%= f.hidden_field :latitude %>
      <%= f.hidden_field :longitude %>
      <%= f.submit "Create Event", class: "btn btn-primary" %>
    <% end %>
    <%= tinymce %>

昨天我尝试将应用程序部署到Heroku。我按照本教程http://railsapps.github.io/rails-heroku-tutorial.html预编译了资产rake assets:precompile命令。

从那时起,我无法在开发和生产环境中使用创建和编辑页面。我得到了JSON :: GeneratorError - &#34;只允许生成一些JSON对象或数组&#34;错误和&lt;%= tinymce%&gt;视图文件底部的行突出显示。这发生在我当地的开发环境中,之前工作正常。

如果我删除&lt;%= tinymce%&gt;从页面,他们加载很好。我尝试在早期的SE线程之后添加rubyracer,execjs和mulit_json gems,但是它没有用。如何摆脱这个?

1 个答案:

答案 0 :(得分:0)

您的教程中链接的官方文档指定了以下用于预编译的命令:RAILS_ENV=production bundle exec rake assets:precompile