File: app/controllers/line_items_controller.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  class: LineItemsController#9
inherits from
  ApplicationController   
has properties
method: index #12
method: show #23
method: new #34
method: edit #44
method: create #51
method: update #72
method: destroy #90

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 LineItemsController < ApplicationController
  10    # GET /line_items
  11    # GET /line_items.xml
  12    def index
  13      @line_items = LineItem.find(:all)
  14 
  15      respond_to do |format|
  16        format.html # index.html.erb
  17        format.xml  { render :xml => @line_items }
  18      end
  19    end
  20 
  21    # GET /line_items/1
  22    # GET /line_items/1.xml
  23    def show
  24      @line_item = LineItem.find(params[:id])
  25 
  26      respond_to do |format|
  27        format.html # show.html.erb
  28        format.xml  { render :xml => @line_item }
  29      end
  30    end
  31 
  32    # GET /line_items/new
  33    # GET /line_items/new.xml
  34    def new
  35      @line_item = LineItem.new
  36 
  37      respond_to do |format|
  38        format.html # new.html.erb
  39        format.xml  { render :xml => @line_item }
  40      end
  41    end
  42 
  43    # GET /line_items/1/edit
  44    def edit
  45      @line_item = LineItem.find(params[:id])
  46    end
  47 
  48    # POST /line_items
  49    # POST /line_items.xml
  50 
  51    def create
  52      params[:line_item][:order_id] ||= params[:order_id]
  53      @line_item = LineItem.new(params[:line_item])
  54 
  55      respond_to do |format|
  56        if @line_item.save
  57          flash[:notice] = 'LineItem was successfully created.'
  58          format.html { redirect_to(@line_item) }
  59          format.xml  { render :xml => @line_item, :status => :created,
  60                               :location => @line_item }
  61        else
  62          format.html { render :action => "new" }
  63          format.xml  { render :xml => @line_item.errors,
  64                               :status => :unprocessable_entity }
  65        end
  66      end
  67    end
  68 
  69 
  70    # PUT /line_items/1
  71    # PUT /line_items/1.xml
  72    def update
  73      @line_item = LineItem.find(params[:id])
  74 
  75      respond_to do |format|
  76        if @line_item.update_attributes(params[:line_item])
  77          flash[:notice] = 'LineItem was successfully updated.'
  78          format.html { redirect_to(@line_item) }
  79          format.xml  { head :ok }
  80        else
  81          format.html { render :action => "edit" }
  82          format.xml  { render :xml => @line_item.errors,
  83                               :status => :unprocessable_entity }
  84        end
  85      end
  86    end
  87 
  88    # DELETE /line_items/1
  89    # DELETE /line_items/1.xml
  90    def destroy
  91      @line_item = LineItem.find(params[:id])
  92      @line_item.destroy
  93 
  94      respond_to do |format|
  95        format.html { redirect_to(line_items_url) }
  96        format.xml  { head :ok }
  97      end
  98    end
  99  end