Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionView::Template::Error: unexpected token at '{{2+2}}'

I'm having trouble integrating JS tests into my rails/angular application. In particular, my test setup is choking on the 8th and final occurrence of {{handlebars}} in this html file, and I cant' figure out what's special about this occurrence.

The problem error comes at line 784 of _form.html.erb:

<textarea class="figures_json col-lg-11 col-md-10 col-xs-9" readonly="readonly" name="dance[figures_json]" id="dance_figures_json">
{{2+2}}</textarea>

And the error is this:

dm@red:~/contra$ rspec ./spec/features/dances/create_spec.rb:7 
Run options: include {:locations=>{"./spec/features/dances/create_spec.rb"=>[7]}}
F

Failures:

  1) Creating dances creates a new dance with non-javascript data
     Failure/Error: JSON.parse figures_json

     ActionView::Template::Error:
       784: unexpected token at '{{2+2}}'
     # ./app/models/dance.rb:10:in `figures'
     # ./app/views/dances/_bodyshow.html.erb:6:in `_app_views_dances__bodyshow_html_erb__2235413439078114529_46217560'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:145:in `block in render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:333:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:143:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `block in instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:309:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:47:in `render_partial'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:21:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/helpers/rendering_helper.rb:32:in `render'
     # ./app/views/dances/show.html.erb:16:in `_app_views_dances_show_html_erb__1493296941766923553_47454680'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:145:in `block in render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:333:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/template.rb:143:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `block in instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:52:in `render_template'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:14:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:42:in `render_template'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:23:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/rendering.rb:100:in `_render_template'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/streaming.rb:217:in `_render_template'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/rendering.rb:83:in `render_to_body'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/renderers.rb:37:in `render_to_body'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/rendering.rb:25:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:16:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/core_ext/benchmark.rb:12:in `ms'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:43:in `render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/base.rb:198:in `process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:10:in `process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:115:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:503:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:88:in `run_callbacks'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/callbacks.rb:19:in `process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rescue.rb:29:in `process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `block in instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164:in `instrument'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/abstract_controller/base.rb:137:in `process'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.3/lib/action_view/rendering.rb:30:in `process'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal.rb:196:in `dispatch'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_controller/metal.rb:237:in `block in action'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:45:in `serve'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:43:in `block in serve'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:30:in `each'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:30:in `serve'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:821:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/warden-1.2.4/lib/warden/manager.rb:35:in `block in call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/warden-1.2.4/lib/warden/manager.rb:34:in `catch'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/warden-1.2.4/lib/warden/manager.rb:34:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/conditionalget.rb:25:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/flash.rb:260:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/cookies.rb:560:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/query_cache.rb:36:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:84:in `run_callbacks'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/web-console-2.2.1/lib/web_console/middleware.rb:39:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/rack/logger.rb:38:in `call_app'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/rack/logger.rb:20:in `block in call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:68:in `block in tagged'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:26:in `tagged'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:68:in `tagged'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/rack/logger.rb:20:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/request_id.rb:21:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.3/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/static.rb:116:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:518:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/railties-4.2.3/lib/rails/application.rb:165:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/urlmap.rb:66:in `block in call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `each'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/server.rb:43:in `call'
     # /home/dm/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
     # ------------------
     # --- Caused by: ---
     # Capybara::ExpectationNotMet:
     #   expected to find css "h1" with text "Call Me" but there were no matches. Also found "Internal Server Error", which matched the selector but not all filters.
     #   /home/dm/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/node/matchers.rb:128:in `block in assert_selector'

Finished in 1.77 seconds (files took 1.59 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/features/dances/create_spec.rb:7 # Creating dances creates a new dance with non-javascript data

Here's a link to my Gemfile.lock so you can see what versions of stuff I'm using.

like image 584
Dave Morse Avatar asked Oct 29 '22 21:10

Dave Morse


1 Answers

Are you sure that problem comes from line 784 of _form.html.erb? I can't find this file in a call stack! Call stack states it chokes on dance.rb#10 and, probably, figures_json contains that {{2+2}} which is not a JSON.

UPDATE

I just had a spare minute to download & look what is actually happening in the app. When you render new action you, actually, send the create action via JS and create the Dance with value {{2+2}} from that _form. While it looks odd to me (why create on just new action?) I figure out the reason – angular does not evaluate expressions inside textarea, you need to bind it to ng-model. So, you want to re-write that textarea as this:

<textarea class="figures_json col-lg-11 col-md-10 col-xs-9" readonly="readonly" name="dance[figures_json]" id="dance_figures_json" ng-model="2+2">
like image 152
shlajin Avatar answered Nov 11 '22 07:11

shlajin