Agile Web Development with Rails, Edition 4
11.2 Iteration F2: Creating an AJAX-Based Cart
10.4 Playtime
11.1 Iteration F1: Moving the Cart
30 (tests|runs), 75 assertions, 0 failures, 0 errors.
<0> expected to be
>=
<1>.
Traceback:
/home/rubys/git/awdwr/edition4/checkdepot.rb:38:in `assert_test_summary'
/home/rubys/git/awdwr/edition4/checkdepot.rb:255:in `block in <class:DepotTest>'
Refactor the cart view into partials, and reference the result from the layout.
Create a "partial" view, for just one line item
edit app/views/line_items/_line_item.html.erb
<tr>
<td><%= line_item.quantity %>×</td>
<td><%= line_item.product.title %></td>
<td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
</tr>
Replace that portion of the view with a callout to the partial
edit app/views/carts/show.html.erb
<p id="notice"><%= notice %></p>
<h2>Your Cart</h2>
<table>
<%= render(@cart.line_items) %>
<tr class="total_line">
<td colspan="2">Total</td>
<td class="total_cell"><%= number_to_currency(@cart.total_price) %></td>
</tr>
</table>
<%= button_to 'Empty cart', @cart, method: :delete,
data: { confirm: 'Are you sure?' } %>
Make a copy as a partial for the cart controller
cp app/views/carts/show.html.erb app/views/carts/_cart.html.erb
Modify the copy to reference the (sub)partial and take input from @cart
edit app/views/carts/_cart.html.erb
<p id="notice"><%= notice %></p>
<h2>Your Cart</h2>
<table>
<%= render(cart.line_items) %>
<tr class="total_line">
<td colspan="2">Total</td>
<td class="total_cell"><%= number_to_currency(cart.total_price) %></td>
</tr>
</table>
<%= button_to 'Empty cart', cart, method: :delete,
data: { confirm: 'Are you sure?' } %>
Keep things DRY
edit app/views/carts/show.html.erb
<p id="notice"><%= notice %></p>
<%= render @cart %>
Reference the partial from the layout.
edit app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Pragprog Books Online Store</title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => 'reload' %>
<%= javascript_include_tag "application", "data-turbolinks-track" => 'reload' %>
<%= csrf_meta_tags %>
</head>
<body class="<%= controller.controller_name %>">
<div id="banner">
<%= image_tag 'logo.svg', alt: 'The Pragmatic Bookshelf' %>
<span class="title"><%= @page_title %></span>
</div>
<div id="columns">
<div id="side">
<div id="cart">
<%= render @cart %>
</div>
<ul>
<li><a href="http://www....">Home</a></li>
<li><a href="http://www..../faq">Questions</a></li>
<li><a href="http://www..../news">News</a></li>
<li><a href="http://www..../contact">Contact</a></li>
</ul>
</div>
<div id="main">
<%= yield %>
</div>
</div>
</body>
</html>
Insert a call in the controller to find the cart
edit app/controllers/store_controller.rb
class StoreController < ApplicationController
include CurrentCart
before_action :set_cart
def index
@products = Product.order(:title)
end
end
Add a small bit of style.
edit app/assets/stylesheets/carts.css.scss
// Place all the styles related to the Carts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.carts, #side #cart {
.item_price, .total_line {
text-align: right;
}
.total_line .total_cell {
font-weight: bold;
border-top: 1px solid #595;
}
}
edit app/assets/stylesheets/application.css.scss
#side {
padding: 1em 2em;
background: #141;
form, div {
display: inline;
}
input {
font-size: small;
}
#cart {
font-size: smaller;
color: white;
table {
border-top: 1px dotted #595;
border-bottom: 1px dotted #595;
margin-bottom: 10px;
}
}
ul {
padding: 0;
li {
list-style: none;
a {
color: #bfb;
font-size: small;
}
}
}
}
Change the redirect to be back to the store.
edit app/controllers/line_items_controller.rb
def create
product = Product.find(params[:product_id])
@line_item = @cart.add_product(product)
respond_to do |format|
if @line_item.save
format.html { redirect_to store_index_url }
format.json { render action: 'show',
status: :created, location: @line_item }
else
format.html { render action: 'new' }
format.json { render json: @line_item.errors,
status: :unprocessable_entity }
end
end
end
Purchase another product.
get /
Your Cart
2×
Rails, Angular, Postgres, and Bootstrap
$90.00
1×
Seven Mobile Apps in Seven Weeks
$26.00
Total
$116.00
Your Pragmatic Catalog
Rails, Angular, Postgres, and Bootstrap
Powerful, Effective, and Efficient Full-Stack Web Development
As a Rails developer, you care about user experience and performance,
but you also want simple and maintainable code. Achieve all that by
embracing the full stack of web development, from styling with
Bootstrap, building an interactive user interface with AngularJS, to
storing data quickly and reliably in PostgreSQL. Take a holistic view of
full-stack development to create usable, high-performing applications,
and learn to use these technologies effectively in a Ruby on Rails
environment.
Ruby Performance Optimization
Why Ruby Is Slow, and How to Fix It
You don’t have to accept slow Ruby or Rails performance. In this
comprehensive guide to Ruby optimization, you’ll learn how to write
faster Ruby code—but that’s just the beginning. See exactly what makes
Ruby and Rails code slow, and how to fix it. Alex Dymo will guide you
through perils of memory and CPU optimization, profiling, measuring,
performance testing, garbage collection, and tuning. You’ll find that
all those “hard” things aren’t so difficult after all, and your code
will run orders of magnitude faster.
Seven Mobile Apps in Seven Weeks
Native Apps, Multiple Platforms
Answer the question “Can we build this for ALL the devices?” with a
resounding YES. This book will help you get there with a real-world
introduction to seven platforms, whether you’re new to mobile or an
experienced developer needing to expand your options. Plus, you’ll find
out which cross-platform solution makes the most sense for your needs.
post /line_items?product_id=3
You are being
redirected .
get http://localhost:3000/store/index
Your Cart
2×
Rails, Angular, Postgres, and Bootstrap
$90.00
2×
Seven Mobile Apps in Seven Weeks
$52.00
Total
$142.00
Your Pragmatic Catalog
Rails, Angular, Postgres, and Bootstrap
Powerful, Effective, and Efficient Full-Stack Web Development
As a Rails developer, you care about user experience and performance,
but you also want simple and maintainable code. Achieve all that by
embracing the full stack of web development, from styling with
Bootstrap, building an interactive user interface with AngularJS, to
storing data quickly and reliably in PostgreSQL. Take a holistic view of
full-stack development to create usable, high-performing applications,
and learn to use these technologies effectively in a Ruby on Rails
environment.
Ruby Performance Optimization
Why Ruby Is Slow, and How to Fix It
You don’t have to accept slow Ruby or Rails performance. In this
comprehensive guide to Ruby optimization, you’ll learn how to write
faster Ruby code—but that’s just the beginning. See exactly what makes
Ruby and Rails code slow, and how to fix it. Alex Dymo will guide you
through perils of memory and CPU optimization, profiling, measuring,
performance testing, garbage collection, and tuning. You’ll find that
all those “hard” things aren’t so difficult after all, and your code
will run orders of magnitude faster.
Seven Mobile Apps in Seven Weeks
Native Apps, Multiple Platforms
Answer the question “Can we build this for ALL the devices?” with a
resounding YES. This book will help you get there with a real-world
introduction to seven platforms, whether you’re new to mobile or an
experienced developer needing to expand your options. Plus, you’ll find
out which cross-platform solution makes the most sense for your needs.
Run tests... oops.
rake test
rake aborted!
ActiveRecord::PendingMigrationError: Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=test' to resolve this issue.
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:383:in `check_pending!'
/home/rubys/git/awdwr/edition4/work-225-40/depot/test/test_helper.rb:6:in `<class:TestCase>'
/home/rubys/git/awdwr/edition4/work-225-40/depot/test/test_helper.rb:5:in `<top (required)>'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `block in require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `require'
/home/rubys/git/awdwr/edition4/work-225-40/depot/test/helpers/carts_helper_test.rb:1:in `<top (required)>'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `block in require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `require'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:73:in `block (3 levels) in define'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:73:in `each'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:73:in `block (2 levels) in define'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:72:in `each'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:72:in `block in define'
/home/rubys/git/rails/railties/lib/rails/test_unit/testing.rake:61:in `block in <top (required)>'
/home/rubys/.rvm/gems/ruby-2.2.5/gems/rake-11.2.1/exe/rake:27:in `<top (required)>'
/home/rubys/.rvm/gems/ruby-2.2.5/bin/ruby_executable_hooks:15:in `eval'
/home/rubys/.rvm/gems/ruby-2.2.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => test:run => test:units
(See full trace by running task with --trace)
Run options: --seed 29500
# Running tests:
Finished tests in 0.000723s, 0.0000 tests/s, 0.0000 assertions/s.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Verify that the products page is indeed broken
get /products
HTTP Response Code: 500
ArgumentError in
Products#index
Showing /home/rubys/git/awdwr/edition4/work-225-40/depot/app/views/layouts/application.html.erb where line #21 raised:
'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.
Extracted source (around line #21 ):
18
19
20
21
22
23
24
<div id="side">
<!-- START_HIGHLIGHT -->
<div id="cart">
<%= render @cart %>
</div>
<!-- END_HIGHLIGHT -->
Rails.root: /home/rubys/git/awdwr/edition4/work-225-40/depot
Application Trace |
Framework Trace |
Full Trace
app/views/layouts/application.html.erb:21:in `_app_views_layouts_application_html_erb__479224710527383373_27837100'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/partial_renderer.rb:436:in `partial_path'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/partial_renderer.rb:345:in `setup'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/partial_renderer.rb:262:in `render'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:47:in `render_partial'
/home/rubys/git/rails/actionpack/lib/action_view/helpers/rendering_helper.rb:27:in `render'
/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:161: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:61:in `render_with_layout'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:47:in `render_template'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:17:in `render'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:42:in `render_template'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:23:in `render'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:127:in `_render_template'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/streaming.rb:219:in `_render_template'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:120: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:26:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:97: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:41: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.2.5/lib/ruby/2.2.0/benchmark.rb:303: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:41:in `block in render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:84: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:40: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:18:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:413:in `_run__1531220322939848058__process_action__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:80: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:31: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/actionpack/lib/abstract_controller/rendering.rb:44:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:195: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:231: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:71: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:676: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:241: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:486: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:626:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:373: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:373:in `_run__3111252526381466796__call__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:80: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: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.rb:83: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:511:in `call'
/home/rubys/git/rails/railties/lib/rails/application.rb:97: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.2.5/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/home/rubys/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/home/rubys/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/partial_renderer.rb:436:in `partial_path'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/partial_renderer.rb:345:in `setup'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/partial_renderer.rb:262:in `render'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:47:in `render_partial'
/home/rubys/git/rails/actionpack/lib/action_view/helpers/rendering_helper.rb:27:in `render'
app/views/layouts/application.html.erb:21:in `_app_views_layouts_application_html_erb__479224710527383373_27837100'
/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:161: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:61:in `render_with_layout'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:47:in `render_template'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/template_renderer.rb:17:in `render'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:42:in `render_template'
/home/rubys/git/rails/actionpack/lib/action_view/renderer/renderer.rb:23:in `render'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:127:in `_render_template'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/streaming.rb:219:in `_render_template'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:120: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:26:in `render_to_body'
/home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:97: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:41: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.2.5/lib/ruby/2.2.0/benchmark.rb:303: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:41:in `block in render'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:84: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:40: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:18:in `block in process_action'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:413:in `_run__1531220322939848058__process_action__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:80: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:31: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/actionpack/lib/abstract_controller/rendering.rb:44:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:195: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:231: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:71: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:676: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:241: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:486: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:626:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:373: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:373:in `_run__3111252526381466796__call__callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:80: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: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.rb:83: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:511:in `call'
/home/rubys/git/rails/railties/lib/rails/application.rb:97: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.2.5/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/home/rubys/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/home/rubys/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Request
Parameters :
None
_csrf_token: "bKQtHS0+sdyAwiYfgtan6hxPkUzeQhJl1/jYh60tGNw="
cart_id: 2
session_id: "05646cd9ba5488c19a08218cf7d1afbf"
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
Check for nil
edit app/views/layouts/application.html.erb
<div id="side">
<div id="cart">
<% if @cart %>
<%= render @cart %>
<% end %>
</div>
<ul>
<li><a href="http://www....">Home</a></li>
<li><a href="http://www..../faq">Questions</a></li>
<li><a href="http://www..../news">News</a></li>
<li><a href="http://www..../contact">Contact</a></li>
</ul>
</div>
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_index_path
end
all better
rake test
rake aborted!
ActiveRecord::PendingMigrationError: Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=test' to resolve this issue.
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:383:in `check_pending!'
/home/rubys/git/awdwr/edition4/work-225-40/depot/test/test_helper.rb:6:in `<class:TestCase>'
/home/rubys/git/awdwr/edition4/work-225-40/depot/test/test_helper.rb:5:in `<top (required)>'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `block in require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `require'
/home/rubys/git/awdwr/edition4/work-225-40/depot/test/helpers/carts_helper_test.rb:1:in `<top (required)>'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `block in require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:229:in `require'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:73:in `block (3 levels) in define'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:73:in `each'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:73:in `block (2 levels) in define'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:72:in `each'
/home/rubys/git/rails/railties/lib/rails/test_unit/sub_test_task.rb:72:in `block in define'
/home/rubys/git/rails/railties/lib/rails/test_unit/testing.rake:61:in `block in <top (required)>'
/home/rubys/.rvm/gems/ruby-2.2.5/gems/rake-11.2.1/exe/rake:27:in `<top (required)>'
/home/rubys/.rvm/gems/ruby-2.2.5/bin/ruby_executable_hooks:15:in `eval'
/home/rubys/.rvm/gems/ruby-2.2.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => test:run => test:units
(See full trace by running task with --trace)
Run options: --seed 45876
# Running tests:
Finished tests in 0.000729s, 0.0000 tests/s, 0.0000 assertions/s.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
11.2 Iteration F2: Creating an AJAX-Based Cart
10.4 Playtime