Agile Web Development with Rails, Edition 4

Table of Contents 14.3 Iteration I3: Limiting Access

14.4 Iteration I4: Adding a Sidebar

Expected at least 1 element matching "legend", found 0.
<0> expected to be
>=
<1>.

Traceback:
  /home/rubys/git/awdwr/edition4/checkdepot.rb:353:in `block in <class:DepotTest>'

Add admin links and a button to Logout

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" => true %>
  <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
  <%= csrf_meta_tags %>
</head>
<body class="<%= controller.controller_name %>">
  <div id="banner">
    <%= image_tag("logo.png") %>
    <%= @page_title || "Pragmatic Bookshelf" %>
  </div>
  <div id="columns">
    <div id="side">
      <% if @cart %>
        <%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %>
          <%= render @cart %>
        <% end %>
      <% end %>
 
      <%= render Order.find(session[:order_id]) if session[:order_id] -%>
 
      <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>
 
      <% if session[:user_id] %>
        <ul>
          <li><%= link_to 'Orders',   orders_path   %></li>
          <li><%= link_to 'Products', products_path %></li>
          <li><%= link_to 'Users',    users_path    %></li>
        </ul>
        <%= button_to 'Logout', logout_path, method: :delete   %>
      <% end %>
    </div>
    <div id="main">
      <%= yield %>
    </div>
  </div>
</body>
</html>

Log out

get /admin

Welcome

It's 2016-01-27 15:57:02 -0500 We have 0 orders.
post /logout

ActionController::InvalidAuthenticityToken in SessionsController#destroy

ActionController::InvalidAuthenticityToken

Extracted source (around line #195):
193
194
195
196
197
198
              
def handle_unverified_request
raise ActionController::InvalidAuthenticityToken
end
end
end

Rails.root: /home/rubys/git/awdwr/edition4/work-230/depot

Application Trace | Framework Trace | Full Trace
/home/rubys/git/rails/actionpack/lib/action_controller/metal/request_forgery_protection.rb:195:in `handle_unverified_request'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/request_forgery_protection.rb:223:in `handle_unverified_request'
/home/rubys/git/rails/actionpack/lib/action_controller/metal/request_forgery_protection.rb:218:in `verify_authenticity_token'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:382:in `block in make_lambda'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:169:in `block (2 levels) in halting'
/home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:12:in `block (2 levels) in <module:Callbacks>'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:170:in `block in halting'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:454:in `block in call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:454:in `each'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:454:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:90: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:27: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:164:in `block in instrument'
/home/rubys/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:164: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:248: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:128: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:192:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_controller/metal.rb:264:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:32:in `serve'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:42:in `block in serve'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:29:in `each'
/home/rubys/git/rails/actionpack/lib/action_dispatch/journey/router.rb:29:in `serve'
/home/rubys/git/rails/actionpack/lib/action_dispatch/routing/route_set.rb:724:in `call'
/home/rubys/git/rails/actionview/lib/action_view/digestor.rb:14:in `call'
rack (2.0.0.alpha) lib/rack/etag.rb:25:in `call'
rack (2.0.0.alpha) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.0.alpha) lib/rack/head.rb:12:in `call'
rack (2.0.0.alpha) lib/rack/session/abstract/id.rb:220:in `context'
rack (2.0.0.alpha) lib/rack/session/abstract/id.rb:214:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/cookies.rb:608: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:963:in `call'
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:558: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:97:in `__run_callbacks__'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
/home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:90: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:71:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
/home/rubys/git/web-console/lib/web_console/middleware.rb:131:in `call_app'
/home/rubys/git/web-console/lib/web_console/middleware.rb:28:in `block in call'
/home/rubys/git/web-console/lib/web_console/middleware.rb:18:in `catch'
/home/rubys/git/web-console/lib/web_console/middleware.rb:18: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:42:in `call_app'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:24:in `block in call'
/home/rubys/git/rails/activesupport/lib/active_support/tagged_logging.rb:70: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:70:in `tagged'
/home/rubys/git/rails/railties/lib/rails/rack/logger.rb:24:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.0.alpha) lib/rack/method_override.rb:22:in `call'
rack (2.0.0.alpha) lib/rack/runtime.rb:22:in `call'
/home/rubys/git/rails/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/load_interlock.rb:13:in `call'
/home/rubys/git/rails/actionpack/lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.0.alpha) lib/rack/sendfile.rb:111:in `call'
/home/rubys/git/rails/railties/lib/rails/engine.rb:522:in `call'
puma (2.15.3) lib/puma/server.rb:541:in `handle_request'
puma (2.15.3) lib/puma/server.rb:388:in `process_client'
puma (2.15.3) lib/puma/server.rb:270:in `block in run'
puma (2.15.3) lib/puma/thread_pool.rb:106:in `block in spawn_thread'

Request

Parameters:

{"submit"=>"Logout", "_method"=>"delete", "authenticity_token"=>"NmMmmjZubV6FCAJaxpNdMR8zlZm3qdUCzo3B7CKkQI8k6OM37fJEkIqDKTxbA4Of2z+yU/9WYV9Sb9+lb0i8vQ=="}

Response

Headers:

None

Demonstrate that everybody can get to the store

get /

Getting started

Here’s how to get rolling:

  1. Use bin/rails generate to create your models and controllers

    To see all available options, run it without parameters.

  2. Set up a root route to replace this page

    You're seeing this page because you're running in development mode and you haven't set a root route yet.

    Routes are set up in config/routes.rb.

  3. Configure your database

    If you're not using SQLite (the default), edit config/database.yml with your username and password.

Demonstrate that login is required to see the products

get /products

cleanup - precompile assets for inclusion in results

rails assets:precompile
I, [2016-01-27T15:59:04.419567 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/cs-f56ef62bc41b040664e801a38f068082a75d506d9048307e8096737463503d0b.jpg
I, [2016-01-27T15:59:04.420653 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/logo-c6cc13d09c4262e637d9af74fa20f7cc0ba8cb57864863b3ce3135f37cbf308c.png
I, [2016-01-27T15:59:04.421413 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/rails-5ad6d454af23f597c4c39dbe4ec6e12784f8e382997a4bc04944ab8547d48881.png
I, [2016-01-27T15:59:04.422305 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/rtp-d3d2240713cce773840785de837acf822d235d1b77040a3e1ed9d8c014cff086.jpg
I, [2016-01-27T15:59:04.423289 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/ruby-836fee16e3757bcd4e2c21d064eee4fa81d7f93e4e9a44b1ffcd6c1d41c92a88.jpg
I, [2016-01-27T15:59:04.481858 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/application-0beb6360ef0a32f1a2822b8e916d122f46fe74a40ec6c7d7cef590875251d588.js
I, [2016-01-27T15:59:04.481983 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/application-0beb6360ef0a32f1a2822b8e916d122f46fe74a40ec6c7d7cef590875251d588.js.gz
I, [2016-01-27T15:59:04.492874 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/application-681214d51f84f98994bcbc030a95533f0a9fc3172883389ce13e3ec6bcfe66e6.css
I, [2016-01-27T15:59:04.493003 #8488]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-230/depot/public/assets/application-681214d51f84f98994bcbc030a95533f0a9fc3172883389ce13e3ec6bcfe66e6.css.gz

Log in

get /login
#<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:3000 (Connection refused - connect(2) for "localhost" port 3000)>
  /home/rubys/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
  /home/rubys/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
  /home/rubys/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
  /home/rubys/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
  /home/rubys/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:878:in `connect'
  /home/rubys/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
  /home/rubys/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:852:in `start'
  /home/rubys/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:584:in `start'
  /home/rubys/git/gorp/lib/gorp/net.rb:107:in `post'
  makedepot.rb:3117:in `block in <main>'
  /home/rubys/git/gorp/lib/gorp/output.rb:59:in `block (4 levels) in <top (required)>'
  /home/rubys/git/gorp/lib/gorp/output.rb:49:in `each'
  /home/rubys/git/gorp/lib/gorp/output.rb:49:in `block (3 levels) in <top (required)>'
  /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures'
  /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!'
  /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing'
  /home/rubys/git/gorp/lib/gorp/output.rb:22:in `block (2 levels) in <top (required)>'
  /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures'
  /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!'
  /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing'
  /home/rubys/git/gorp/lib/gorp/output.rb:11:in `block in <top (required)>'
    

Table of Contents 14.3 Iteration I3: Limiting Access