File: app/controllers/admin_controller.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  class: AdminController#9
inherits from
  ApplicationController   
has properties
method: login #14
method: logout #28
method: index #36

Class Hierarchy

Code

   1  #---
   2  # Excerpted from "Agile Web Development with Rails, 3rd Ed.",
   3  # published by The Pragmatic Bookshelf.
   4  # Copyrights apply to this code. It may not be used to create training material, 
   5  # courses, books, articles, and the like. Contact us if you are in doubt.
   6  # We make no guarantees that this code is fit for any purpose. 
   7  # Visit http://www.pragmaticprogrammer.com/titles/rails3 for more book information.
   8  #---
   9  class AdminController < ApplicationController
  10 
  11    # just display the form and wait for user to
  12    # enter a name and password
  13    
  14    def login
  15      if request.post?
  16        user = User.authenticate(params[:name], params[:password])
  17        if user
  18          session[:user_id] = user.id
  19          redirect_to(:action => "index")
  20        else
  21          flash.now[:notice] = "Invalid user/password combination"
  22        end
  23      end
  24    end
  25    
  26 
  27    
  28    def logout
  29      session[:user_id] = :logged_out
  30      flash[:notice] = "Logged out"
  31      redirect_to(:action => "login")
  32    end
  33    
  34 
  35    
  36    def index
  37      @total_orders = Order.count
  38    end
  39    
  40  end