The Depot Application

11.4 Iteration F4: Adding a Sidebar, More Administration 11.2 Iteration F2: Logging in

11.3 Iteration F3: Limiting Access

Expected at least 1 element matching "a[href='http://localhost:3000/admin/login']", found 0.

Traceback:
  /home/rubys/git/awdwr/edition3/work-187-23/vendor/rails/actionpack/lib/action_controller/assertions/selector_assertions.rb:307:in `assert_select'
  /home/rubys/git/awdwr/edition3/checkdepot.rb:182
edit app/controllers/application_controller.rb
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
 
class ApplicationController < ActionController::Base
  before_filter :authorize, :except => :login
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
 
  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
    
protected
  def authorize
    unless User.find_by_id(session[:user_id])
      flash[:notice] = "Please log in"
      redirect_to :controller => 'admin', :action => 'login'
    end
  end
end
edit app/controllers/store_controller.rb
class StoreController < ApplicationController
  def index
    @products = Product.find_products_for_sale
    @cart = find_cart
  end
 
 
  def add_to_cart
    product = Product.find(params[:id])
    @cart = find_cart
    @current_item = @cart.add_product(product)
    respond_to do |format|
      format.js if request.xhr?
      format.html {redirect_to_index}
    end
  rescue ActiveRecord::RecordNotFound
    logger.error("Attempt to access invalid product #{params[:id]}")
    redirect_to_index("Invalid product")
  end
 
  def checkout
    @cart = find_cart
    if @cart.items.empty?
      redirect_to_index("Your cart is empty")
    else
      @order = Order.new
    end
  end
 
  def save_order
    @cart = find_cart
    @order = Order.new(params[:order])
    @order.add_line_items_from_cart(@cart)
    if @order.save
      session[:cart] = nil
      redirect_to_index("Thank you for your order")
    else
      render :action => 'checkout'
    end
  end
 
  def empty_cart
    session[:cart] = nil
    redirect_to_index
  end
 
private
 
  def redirect_to_index(msg = nil)
    flash[:notice] = msg if msg
    redirect_to :action => 'index'
  end
 
  def find_cart
    session[:cart] ||= Cart.new
  end
 
end
edit app/controllers/store_controller.rb
class StoreController < ApplicationController
  #...
protected
 
  def authorize
  end
end
rake db:sessions:clear
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /home/rubys/git/awdwr/edition3/work-187-23/depot/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#initialize is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#initialize called from /home/rubys/git/awdwr/edition3/work-187-23/depot/config/../vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:100.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /home/rubys/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /home/rubys/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /home/rubys/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /home/rubys/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /home/rubys/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /home/rubys/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91.
rake aborted!
no such file to load -- rake/rdoctask
/home/rubys/git/awdwr/edition3/work-187-23/depot/Rakefile:8
(See full trace by running task with --trace)
get /admin/logout

ActiveRecord::StatementInvalid in AdminController#logout

Could not find table 'users'

RAILS_ROOT: /home/rubys/git/awdwr/edition3/work-187-23/depot

Application Trace | Framework Trace | Full Trace

Request

Parameters:

None

Show session dump

Response

Headers:

{"Cache-Control"=>"no-cache",
 "Content-Type"=>""}
get /store

ActiveRecord::StatementInvalid in StoreController#index

SQLite3::SQLException: no such table: products: SELECT * FROM "products"  ORDER BY title

RAILS_ROOT: /home/rubys/git/awdwr/edition3/work-187-23/depot

Application Trace | Framework Trace | Full Trace

Request

Parameters:

None

Show session dump

Response

Headers:

{"Cache-Control"=>"no-cache",
 "Content-Type"=>""}
get /products

ActiveRecord::StatementInvalid in ProductsController#index

Could not find table 'users'

RAILS_ROOT: /home/rubys/git/awdwr/edition3/work-187-23/depot

Application Trace | Framework Trace | Full Trace

Request

Parameters:

None

Show session dump

Response

Headers:

{"Cache-Control"=>"no-cache",
 "Content-Type"=>""}
get /admin/login

ActiveRecord::StatementInvalid in Admin#login

Showing app/views/admin/login.html.erb where line #2 raised:

  Could not find table 'sessions'

Extracted source (around line #2):

  1: <div class="depot-form">
2:   <% form_tag do %>
3:     <fieldset>
4:       <legend>Please Log In</legend>
5: 

RAILS_ROOT: /home/rubys/git/awdwr/edition3/work-187-23/depot

Application Trace | Framework Trace | Full Trace
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:29:in `table_structure'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `tap'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:228:in `columns'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1305:in `columns'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1313:in `columns_hash'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/session_store.rb:93:in `setup_sessid_compatibility!'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/session_store.rb:62:in `find_by_session_id'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/session_store.rb:330:in `find_session'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/session_store.rb:290:in `get_session'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1482:in `silence'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/activerecord/lib/active_record/session_store.rb:288:in `get_session'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb:221:in `load_session'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb:258:in `stale_session_check!'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb:219:in `load_session'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb:132:in `send'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb:132:in `load!'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb:128:in `load_for_write!'
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb:67:in `[]='
/home/rubys/git/awdwr/edition3/work-187-23/depot/vendor/rails/actionpack/lib/action_controller/request_forgery_protection.rb:109:in `form_authenticity_token'
(eval):2:in `send'
(eval):2:in `form_authenticity_token'

Request

Parameters:

None

Show session dump

Response

Headers:

{"Cache-Control"=>"no-cache",
 "Content-Type"=>"text/html"}
get /products

ActiveRecord::StatementInvalid in ProductsController#index

Could not find table 'users'

RAILS_ROOT: /home/rubys/git/awdwr/edition3/work-187-23/depot

Application Trace | Framework Trace | Full Trace

Request

Parameters:

None

Show session dump

Response

Headers:

{"Cache-Control"=>"no-cache",
 "Content-Type"=>""}

11.4 Iteration F4: Adding a Sidebar, More Administration 11.2 Iteration F2: Logging in