Sha256: de17d27d5e681f43b29ec00406c092e53783fd6384842ab2d0bf562d0f62d617

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require_dependency "expense_gun/application_controller"

module ExpenseGun
  class ExpenseLinesController < ApplicationController
    before_action :set_objects
    
    def index
      redirect_to expense_path(@expense)
    end
    
    def new
      authorize! :edit, @expense
      
      @expense_line = @expense.expense_lines.new
    end
    
    def create
      authorize! :edit, @expense
      
      @expense_line = @expense.expense_lines.new(expense_line_params)
      
      if @expense_line.save
        flash[:success] = "Expense line created"
        redirect_to expense_path(@expense)
      else
        render :new
      end
    end
    
    def edit
      authorize! :edit, @expense
    end
    
    def update
      authorize! :edit, @expense
      
      if @expense_line.update_attributes(expense_line_params)
        flash[:success] = "Expense line updated"
        redirect_to expense_path(@expense)
      else
        render :edit
      end
    end
    
    def destroy
      authorize! :edit, @expense
      
      @expense_line.destroy
      flash[:success] = "Expense line destroyed"
      redirect_to expense_path(@expense)
    end
    
    private
    
    def set_objects
      @expense      = Expense.find params[:expense_id]
      @expense_line = ExpenseLine.find params[:id] if params[:id].present?
    end
    
    def expense_line_params
      params.require(:expense_line).permit!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
expense_gun-1.0.0 app/controllers/expense_gun/expense_lines_controller.rb