Agile Web Development with Rails, Edition 4
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-192/depot/app/views/layouts/application.html.erb where line #20 raised:
undefined method `line_items' for nil:NilClass
Extracted source (around line #20):
17: <div id="side">
18: <!-- START_HIGHLIGHT -->
19: <!-- START:hidden_div -->
20: <%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %>
21: <%= render @cart %>
22: <% end %>
23: <!-- END:hidden_div -->
Rails.root: /home/rubys/git/awdwr/edition4/work-192/depot
Application Trace |
Framework Trace |
Full Trace
app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb___3675413776673404080_37486820'
app/controllers/products_controller.rb:7:in `index'
/home/rubys/git/rails/activesupport/lib/active_support/whiny_nil.rb:48:in `method_missing'
/home/rubys/git/rails/actionpack/lib/action_view/template.rb:143:in `block in render'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:55:in `instrument'
/home/rubys/git/rails/actionpack/lib/action_view/template.rb:141:in `render'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:51:in `render_with_layout'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:37:in `render_template'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:12:in `render'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:36:in `render_template'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:17:in `render'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:120:in `_render_template'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/streaming.rb:225:in `_render_template'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:114:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/renderers.rb:30:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/compatibility.rb:43:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:99: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:40:in `block (2 levels) in render'
/home/rubys/git/rails/activesupport/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/rubys/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
/home/rubys/git/rails/activesupport/lib/active_support/core_ext/benchmark.rb:5:in `ms'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
/home/rubys/git/rails/activerecord/lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:39: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/mime_responds.rb:268:in `block in retrieve_response_from_mimes'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/mime_responds.rb:195:in `call'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/mime_responds.rb:195:in `respond_to'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/rubys/git/rails/actionpack/lib/abstract_controller/base.rb:167: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:18:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:416:in `_run__1438071545763638432__process_action__1925877240067281996__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rescue.rb:17:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:53: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:53:in `instrument'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:198: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:121:in `process'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:45:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:193:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:236:in `block in action'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:66:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:30:in `call'
/home/rubys/git/journey/lib/journey/router.rb:60:in `block in call'
/home/rubys/git/journey/lib/journey/router.rb:48:in `each'
/home/rubys/git/journey/lib/journey/router.rb:48:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:570:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.5) lib/rack/etag.rb:23:in `call'
rack (1.3.5) lib/rack/conditionalget.rb:25:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/head.rb:14:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/flash.rb:247:in `call'
rack (1.3.5) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.5) lib/rack/session/abstract/id.rb:190:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/cookies.rb:342:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/query_cache.rb:64:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:81: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:68:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:48:in `call'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:26:in `call_app'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:16:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.3.5) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.5) lib/rack/runtime.rb:17:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.5) lib/rack/lock.rb:15:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/static.rb:53:in `call'
/home/rubys/git/rails/railties/lib/rails/engine.rb:459:in `call'
rack (1.3.5) lib/rack/content_length.rb:14:in `call'
/home/rubys/git/rails/railties/lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.5) lib/rack/handler/webrick.rb:59:in `service'
/home/rubys/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/rubys/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/rubys/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
/home/rubys/git/rails/activesupport/lib/active_support/whiny_nil.rb:48:in `method_missing'
app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb___3675413776673404080_37486820'
/home/rubys/git/rails/actionpack/lib/action_view/template.rb:143:in `block in render'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:55:in `instrument'
/home/rubys/git/rails/actionpack/lib/action_view/template.rb:141:in `render'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:51:in `render_with_layout'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:37:in `render_template'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:12:in `render'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:36:in `render_template'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:17:in `render'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:120:in `_render_template'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/streaming.rb:225:in `_render_template'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:114:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/renderers.rb:30:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/compatibility.rb:43:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:99: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:40:in `block (2 levels) in render'
/home/rubys/git/rails/activesupport/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/rubys/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
/home/rubys/git/rails/activesupport/lib/active_support/core_ext/benchmark.rb:5:in `ms'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
/home/rubys/git/rails/activerecord/lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:39: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/mime_responds.rb:268:in `block in retrieve_response_from_mimes'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/mime_responds.rb:195:in `call'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/mime_responds.rb:195:in `respond_to'
app/controllers/products_controller.rb:7:in `index'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/rubys/git/rails/actionpack/lib/abstract_controller/base.rb:167: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:18:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:416:in `_run__1438071545763638432__process_action__1925877240067281996__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rescue.rb:17:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:53: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:53:in `instrument'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:198: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:121:in `process'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:45:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:193:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:236:in `block in action'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:66:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:30:in `call'
/home/rubys/git/journey/lib/journey/router.rb:60:in `block in call'
/home/rubys/git/journey/lib/journey/router.rb:48:in `each'
/home/rubys/git/journey/lib/journey/router.rb:48:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:570:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.5) lib/rack/etag.rb:23:in `call'
rack (1.3.5) lib/rack/conditionalget.rb:25:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/head.rb:14:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/flash.rb:247:in `call'
rack (1.3.5) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.5) lib/rack/session/abstract/id.rb:190:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/cookies.rb:342:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/query_cache.rb:64:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:81: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:68:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:48:in `call'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:26:in `call_app'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:16:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.3.5) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.5) lib/rack/runtime.rb:17:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.5) lib/rack/lock.rb:15:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/static.rb:53:in `call'
/home/rubys/git/rails/railties/lib/rails/engine.rb:459:in `call'
rack (1.3.5) lib/rack/content_length.rb:14:in `call'
/home/rubys/git/rails/railties/lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.5) lib/rack/handler/webrick.rb:59:in `service'
/home/rubys/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/rubys/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/rubys/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Request
Parameters:
None
Show session dump
_csrf_token: "shxSsrJ4EsgZCfGU77/yrLqmnj0IuoeBHqTEtkctYs4="
cart_id: 3
session_id: "ce987df21f6392f8d8e8799cda3d22d8"
Show env dump
GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "localhost"
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/functional/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/functional/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/functional/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
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
.......
Finished in 0.549360 seconds.
7 tests, 28 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 26847
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
.........................
Finished in 1.382250 seconds.
25 tests, 42 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 12595
Save our progress
git commit -a -m "AJAX"
[master 35c7c6f] AJAX
3 files changed, 30 insertions(+), 12 deletions(-)
git tag iteration-f
12.1 Iteration G1: Capturing an Order
11.5 Iteration F5: Making Images Clickable