Rails: Can't render pages, getting JSON parse error

怎甘沉沦 提交于 2020-01-24 17:12:13

问题


I am working on a project that uses a Rails server while using JSPM to organize Javascript files while also using Sprockets to pipeline assets.

My rails server works, but I cannot currently render any views. I think this has something to do with sprockets not successfully managing the processors that compiles the JavaScript. (An additional note: the JavaScript is is ES6). What the below error seems to be saying is that the server tries to render the index page, but the JSON is absent because the JS is not compiled (my guess). This said, I really have no idea how to fix this problem.

The error is below:

`JSON::ParserError in Application#index

Showing /Users/ben/agora/app/views/layouts/application.html.erb where line #14 raised:

A JSON text must at least contain two octets!
  (in /Users/ben/agora/app/assets/javascripts/bundles/application.js.sfx)
Extracted source (around line #14):

11: <%= yield %>
12: 
13: <%= render_react_page %>
14: <%= javascript_include_tag 'bundles/application' %>
15: </body>
16: </html>`

The full stack trace is as follows:

`json (1.8.2) lib/json/common.rb:155:in `initialize'
json (1.8.2) lib/json/common.rb:155:in `new'
json (1.8.2) lib/json/common.rb:155:in `parse'
vendor/gems/jspm-rails/lib/jspm/sfx/template.rb:30:in `block in evaluate'
/Users/ben/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/open3.rb:199:in `popen_run'
/Users/ben/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/open3.rb:93:in `popen3'
vendor/gems/jspm-rails/lib/jspm/sfx/template.rb:24:in `evaluate'
tilt (1.4.1) lib/tilt/template.rb:103:in `render'
sprockets (2.2.3) lib/sprockets/context.rb:193:in `block in evaluate'
sprockets (2.2.3) lib/sprockets/context.rb:190:in `each'
sprockets (2.2.3) lib/sprockets/context.rb:190:in `evaluate'
sprockets (2.2.3) lib/sprockets/processed_asset.rb:12:in `initialize'
sprockets (2.2.3) lib/sprockets/base.rb:249:in `new'
sprockets (2.2.3) lib/sprockets/base.rb:249:in `block in build_asset'
sprockets (2.2.3) lib/sprockets/base.rb:270:in `circular_call_protection'
sprockets (2.2.3) lib/sprockets/base.rb:248:in `build_asset'
sprockets (2.2.3) lib/sprockets/index.rb:93:in `block in build_asset'
sprockets (2.2.3) lib/sprockets/caching.rb:19:in `cache_asset'
sprockets (2.2.3) lib/sprockets/index.rb:92:in `build_asset'
sprockets (2.2.3) lib/sprockets/base.rb:169:in `find_asset'
sprockets (2.2.3) lib/sprockets/index.rb:60:in `find_asset'
sprockets (2.2.3) lib/sprockets/bundled_asset.rb:16:in `initialize'
sprockets (2.2.3) lib/sprockets/base.rb:252:in `new'
sprockets (2.2.3) lib/sprockets/base.rb:252:in `build_asset'
sprockets (2.2.3) lib/sprockets/index.rb:93:in `block in build_asset'
sprockets (2.2.3) lib/sprockets/caching.rb:19:in `cache_asset'
sprockets (2.2.3) lib/sprockets/index.rb:92:in `build_asset'
sprockets (2.2.3) lib/sprockets/base.rb:169:in `find_asset'
sprockets (2.2.3) lib/sprockets/index.rb:60:in `find_asset'
sprockets (2.2.3) lib/sprockets/environment.rb:78:in `find_asset'
sprockets (2.2.3) lib/sprockets/base.rb:177:in `[]'
actionpack (3.2.18) lib/sprockets/helpers/rails_helper.rb:126:in `asset_for'
actionpack (3.2.18) lib/sprockets/helpers/rails_helper.rb:27:in `block in javascript_include_tag'
actionpack (3.2.18) lib/sprockets/helpers/rails_helper.rb:26:in `collect'
actionpack (3.2.18) lib/sprockets/helpers/rails_helper.rb:26:in `javascript_include_tag'
app/views/layouts/application.html.erb:14:in `_app_views_layouts_application_html_erb___4438127222864099562_70202749532280'
actionpack (3.2.18) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.18) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.18) lib/action_view/template.rb:143:in `render'
actionpack (3.2.18) lib/action_view/renderer/template_renderer.rb:59:in `render_with_layout'
actionpack (3.2.18) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.18) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.18) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.18) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.18) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.18) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.18) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.18) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.18) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.18) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.18) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.18) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.18) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/ben/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (3.2.18) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.18) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.18) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
sequel-rails (0.9.11) lib/sequel_rails/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.18) lib/action_controller/metal/instrumentation.rb:39:in `render'
app/controllers/application_controller.rb:7:in `index'
actionpack (3.2.18) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.18) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.18) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.18) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.18) lib/active_support/callbacks.rb:414:in `_run__749368673318476381__process_action__3475398207843127101__callbacks'
activesupport (3.2.18) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.18) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.18) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.18) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.18) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.18) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.18) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.18) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.18) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.18) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.18) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
sequel-rails (0.9.11) lib/sequel_rails/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.18) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.18) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.18) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.18) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.18) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.18) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.18) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.18) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.18) lib/action_dispatch/routing/route_set.rb:608:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/cookies.rb:341:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.18) lib/active_support/callbacks.rb:405:in `_run__103614042811221451__call__1909597293413008327__callbacks'
activesupport (3.2.18) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.18) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.18) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.18) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.18) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.18) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.18) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.18) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.18) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.18) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.18) lib/rails/engine.rb:484:in `call'
railties (3.2.18) lib/rails/application.rb:231:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.18) lib/rails/rack/log_tailer.rb:17:in `call'
thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.3) lib/thin/connection.rb:84:in `catch'
thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.3) lib/thin/connection.rb:53:in `process'
thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.7) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.7) lib/eventmachine.rb:187:in `run'
thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
thin (1.6.3) lib/thin/server.rb:162:in `start'
rack (1.4.5) lib/rack/handler/thin.rb:13:in `run'
rack (1.4.5) lib/rack/server.rb:268:in `start'
railties (3.2.18) lib/rails/commands/server.rb:70:in `start'
railties (3.2.18) lib/rails/commands.rb:55:in `block in <top (required)>'
railties (3.2.18) lib/rails/commands.rb:50:in `tap'
railties (3.2.18) lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'`

回答1:


Would need to see the gemfile for this. The guess is that you are missing the JS runtime which leads to JS not being compiled which leads to missing JSON.

Look at: Rails 3.1 issue with javascript_include_tag in application.html.erb (answer from @Confusion)




回答2:


You Should upgrade ruby in order to solve this issue.



来源:https://stackoverflow.com/questions/32022243/rails-cant-render-pages-getting-json-parse-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!