Sha256: e346abdac068b0ca7a622661dbb6c7959e95935390c6dd9f57c522d57833e1cd

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require_dependency "bookkeeper/application_controller"

module Bookkeeper
  class PurchasesController < ApplicationController
    def index
      @purchases = Purchase.all

      respond_to do |format|
        format.html
        format.json { render json: @purchases }
      end
    end

    def show
      @purchase = Purchase.find(params[:id])

      respond_to do |format|
        format.html
        format.json { render json: @purchase }
      end
    end

    def new
      @purchase = Purchase.new

      respond_to do |format|
        format.html
        format.json { render json: @purchase }
      end
    end

    def edit
      @purchase = Purchase.find(params[:id])
    end

    def create
      @purchase = Purchase.new(params[:purchase])

      respond_to do |format|
        if @purchase.save
          format.html { redirect_to purchases_path, notice: 'Purchase was successfully created.' }
          format.json { render json: @purchase, status: :created, location: @purchase }
        else
          format.html { render action: "new" }
          format.json { render json: @purchase.errors, status: :unprocessable_entity }
        end
      end
    end

    def update
      @purchase = Purchase.find(params[:id])

      respond_to do |format|
        if @purchase.update_attributes(params[:purchase])
          format.html { redirect_to purchases_path, notice: 'Purchase was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: "edit" }
          format.json { render json: @purchase.errors, status: :unprocessable_entity }
        end
      end
    end

    def destroy
      @purchase = Purchase.find(params[:id])
      @purchase.destroy

      respond_to do |format|
        format.html { redirect_to purchases_url }
        format.json { head :no_content }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bookkeeper-0.0.1.beta1 app/controllers/bookkeeper/purchases_controller.rb