Agile Web Development with Rails, Edition 4
12.1 Iteration G1: Capturing an Order
11.5 Iteration F5: Making Images Clickable
11.6 Iteration F6: Testing AJAX changes
Verify that yes, indeed, the product index is broken.
get /products
NoMethodError in
Products#index
Showing /home/rubys/git/awdwr/edition4/work-41/depot/app/views/layouts/application.html.erb where line #21 raised:
undefined method `line_items' for nil:NilClass
Extracted source (around line #21):
18
19
20
21
22
23
24
|
<div id="side">
<!-- START_HIGHLIGHT -->
<!-- START:hidden_div -->
<%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %>
<%= render @cart %>
<% end %>
<!-- END:hidden_div -->
|
Rails.root: /home/rubys/git/awdwr/edition4/work-41/depot
Application Trace |
Framework Trace |
Full Trace
app/views/layouts/application.html.erb:21:in `_app_views_layouts_application_html_erb__947438553114484201_17475960'
/home/rubys/git/rails/actionview/lib/action_view/template.rb:145:in `block in render'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:161:in `instrument'
/home/rubys/git/rails/actionview/lib/action_view/template.rb:339:in `instrument'
/home/rubys/git/rails/actionview/lib/action_view/template.rb:143:in `render'
/home/rubys/git/rails/actionview/lib/action_view/renderer/template_renderer.rb:67:in `render_with_layout'
/home/rubys/git/rails/actionview/lib/action_view/renderer/template_renderer.rb:53:in `render_template'
/home/rubys/git/rails/actionview/lib/action_view/renderer/template_renderer.rb:17:in `render'
/home/rubys/git/rails/actionview/lib/action_view/renderer/renderer.rb:42:in `render_template'
/home/rubys/git/rails/actionview/lib/action_view/renderer/renderer.rb:23:in `render'
/home/rubys/git/rails/actionview/lib/action_view/rendering.rb:99:in `_render_template'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/streaming.rb:217:in `_render_template'
/home/rubys/git/rails/actionview/lib/action_view/rendering.rb:82:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/renderers.rb:32:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:25:in `render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:16:in `render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
/home/rubys/git/rails/activesupport/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/home/rubys/git/rails/activesupport/lib/active_support/core_ext/benchmark.rb:12:in `ms'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
/home/rubys/git/rails/activerecord/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:43:in `render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
/home/rubys/git/rails/actionpack/lib/abstract_controller/base.rb:189:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:10:in `process_action'
/home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:113:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:113:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:552:in `block (2 levels) in compile'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:502:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:502:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:86:in `run_callbacks'
/home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:19:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:159:in `block in instrument'
/home/rubys/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:159:in `instrument'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
/home/rubys/git/rails/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/rubys/git/rails/actionpack/lib/abstract_controller/base.rb:136:in `process'
/home/rubys/git/rails/actionview/lib/action_view/rendering.rb:30:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:196:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:232:in `block in action'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:82:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:50:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:73:in `block in call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:59:in `each'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:59:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:692:in `call'
rack (1.5.5) lib/rack/etag.rb:23:in `call'
rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.5) lib/rack/head.rb:11:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/cookies.rb:562:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/query_cache.rb:36:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:380:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:82:in `run_callbacks'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/reloader.rb:73:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:38:in `call_app'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:20:in `block in call'
/home/rubys/git/rails/activesupport/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/home/rubys/git/rails/activesupport/lib/active_support/tagged_logging.rb:26:in `tagged'
/home/rubys/git/rails/activesupport/lib/active_support/tagged_logging.rb:68:in `tagged'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:20:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
/home/rubys/git/rails/railties/lib/rails/engine.rb:514:in `call'
/home/rubys/git/rails/railties/lib/rails/application.rb:144:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
app/views/layouts/application.html.erb:21:in `_app_views_layouts_application_html_erb__947438553114484201_17475960'
/home/rubys/git/rails/actionview/lib/action_view/template.rb:145:in `block in render'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:161:in `instrument'
/home/rubys/git/rails/actionview/lib/action_view/template.rb:339:in `instrument'
/home/rubys/git/rails/actionview/lib/action_view/template.rb:143:in `render'
/home/rubys/git/rails/actionview/lib/action_view/renderer/template_renderer.rb:67:in `render_with_layout'
/home/rubys/git/rails/actionview/lib/action_view/renderer/template_renderer.rb:53:in `render_template'
/home/rubys/git/rails/actionview/lib/action_view/renderer/template_renderer.rb:17:in `render'
/home/rubys/git/rails/actionview/lib/action_view/renderer/renderer.rb:42:in `render_template'
/home/rubys/git/rails/actionview/lib/action_view/renderer/renderer.rb:23:in `render'
/home/rubys/git/rails/actionview/lib/action_view/rendering.rb:99:in `_render_template'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/streaming.rb:217:in `_render_template'
/home/rubys/git/rails/actionview/lib/action_view/rendering.rb:82:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/renderers.rb:32:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:25:in `render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:16:in `render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
/home/rubys/git/rails/activesupport/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/home/rubys/git/rails/activesupport/lib/active_support/core_ext/benchmark.rb:12:in `ms'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
/home/rubys/git/rails/activerecord/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:43:in `render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
/home/rubys/git/rails/actionpack/lib/abstract_controller/base.rb:189:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:10:in `process_action'
/home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:113:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:113:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:552:in `block (2 levels) in compile'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:502:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:502:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:86:in `run_callbacks'
/home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:19:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:159:in `block in instrument'
/home/rubys/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:159:in `instrument'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
/home/rubys/git/rails/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/rubys/git/rails/actionpack/lib/abstract_controller/base.rb:136:in `process'
/home/rubys/git/rails/actionview/lib/action_view/rendering.rb:30:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:196:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:232:in `block in action'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:82:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:50:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:73:in `block in call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:59:in `each'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:59:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:692:in `call'
rack (1.5.5) lib/rack/etag.rb:23:in `call'
rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.5) lib/rack/head.rb:11:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/cookies.rb:562:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/query_cache.rb:36:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:380:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:82:in `run_callbacks'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/reloader.rb:73:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:38:in `call_app'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:20:in `block in call'
/home/rubys/git/rails/activesupport/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/home/rubys/git/rails/activesupport/lib/active_support/tagged_logging.rb:26:in `tagged'
/home/rubys/git/rails/activesupport/lib/active_support/tagged_logging.rb:68:in `tagged'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:20:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
/home/rubys/git/rails/railties/lib/rails/engine.rb:514:in `call'
/home/rubys/git/rails/railties/lib/rails/application.rb:144:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Request
Parameters:
None
_csrf_token: "itCt0rYkueJSTlbP/MA3ckN2aZ4nb3iNo4fA7LGXaC0="
cart_id: 4
session_id: "333bd60b19448eade617f941d6807534"
GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html"
HTTP_ACCEPT_ENCODING: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"
Response
Headers:
None
Conditionally display the cart.
edit app/views/layouts/application.html.erb
<% if @cart %>
<%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %>
<%= render @cart %>
<% end %>
<% end %>
Update the redirect test.
edit test/controllers/line_items_controller_test.rb
test "should create line_item" do
assert_difference('LineItem.count') do
post :create, product_id: products(:ruby).id
end
assert_redirected_to store_path
end
Add an XHR test.
edit test/controllers/line_items_controller_test.rb
test "should create line_item via ajax" do
assert_difference('LineItem.count') do
xhr :post, :create, product_id: products(:ruby).id
end
assert_response :success
assert_select_jquery :html, '#cart' do
assert_select 'tr#current_item td', /Programming Ruby 1.9/
end
end
Add an test in support for the coffeescript changes.
edit test/controllers/store_controller_test.rb
test "markup needed for store.js.coffee is in place" do
get :index
assert_select '.store .entry > img', 3
assert_select '.entry input[type=submit]', 3
end
Run the tests again.
rake test
Run options: --seed 6037
# Running:
................................
Finished in 0.320617s, 99.8075 runs/s, 249.5186 assertions/s.
32 runs, 80 assertions, 0 failures, 0 errors, 0 skips
Save our progress
git commit -a -m "AJAX"
[master 333c115] AJAX
5 files changed, 48 insertions(+), 19 deletions(-)
git tag iteration-f
12.1 Iteration G1: Capturing an Order
11.5 Iteration F5: Making Images Clickable