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-200-40/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-200-40/depot
Application Trace |
Framework Trace |
Full Trace
app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb__3512295703123559811_32410120'
app/controllers/products_controller.rb:7:in `index'
/home/rubys/git/rails/actionpack/lib/action_view/template.rb:142:in `block in render'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:125:in `instrument'
/home/rubys/git/rails/actionpack/lib/action_view/template.rb:140: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:10: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:108:in `_render_template'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/streaming.rb:224:in `_render_template'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:102:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:33:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:87: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-head-n34575/lib/ruby/2.0.0/benchmark.rb:295: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:83: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:196: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:374:in `_run__3090043643254914370__process_action__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:366:in `__run_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:79: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:29: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:123: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:123: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:204: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:44:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:197: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:240:in `block in action'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:67:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:67: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:68:in `block in call'
/home/rubys/git/journey/lib/journey/router.rb:56:in `each'
/home/rubys/git/journey/lib/journey/router.rb:56:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:586:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) 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:224:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/cookies.rb:347:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/query_cache.rb:35:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:416: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:366:in `_run__4102902303491471926__call__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:366:in `__run_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:79: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:64:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:33:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:31: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.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) 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.4.1) 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:479:in `call'
/home/rubys/git/rails/railties/lib/rails/application.rb:209:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/webrick/server.rb:191:in `block in start_thread'
app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb__3512295703123559811_32410120'
/home/rubys/git/rails/actionpack/lib/action_view/template.rb:142:in `block in render'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:125:in `instrument'
/home/rubys/git/rails/actionpack/lib/action_view/template.rb:140: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:10: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:108:in `_render_template'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/streaming.rb:224:in `_render_template'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:102:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:33:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:87: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-head-n34575/lib/ruby/2.0.0/benchmark.rb:295: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:83: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:196: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:374:in `_run__3090043643254914370__process_action__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:366:in `__run_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:79: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:29: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:123: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:123: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:204: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:44:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:197: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:240:in `block in action'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:67:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:67: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:68:in `block in call'
/home/rubys/git/journey/lib/journey/router.rb:56:in `each'
/home/rubys/git/journey/lib/journey/router.rb:56:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:586:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) 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:224:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/cookies.rb:347:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/query_cache.rb:35:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:416: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:366:in `_run__4102902303491471926__call__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:366:in `__run_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:79: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:64:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:33:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:31: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.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) 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.4.1) 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:479:in `call'
/home/rubys/git/rails/railties/lib/rails/application.rb:209:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/webrick/server.rb:191:in `block in start_thread'
Request
Parameters:
None
Show session dump
_csrf_token: "eFmGYNDeZfs/ckMgyBEX6MNLz+xlDT6AOXcLxsGLHG0="
cart_id: 3
session_id: "ff5277864df575f95d31ac12640f70b0"
Show env dump
GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html"
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/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
Run options: --seed 8016
# Running tests:
.......
Finished tests in 0.655742s, 10.6749 tests/s, 42.6997 assertions/s.
7 tests, 28 assertions, 0 failures, 0 errors, 0 skips
Run options: --seed 26197
# Running tests:
.........................
Finished tests in 1.185789s, 21.0830 tests/s, 43.8527 assertions/s.
25 tests, 52 assertions, 0 failures, 0 errors, 0 skips
Save our progress
git commit -a -m "AJAX"
[master 4a9a17b] 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