6dd89038d3
close #21
82 lines
2.0 KiB
Ruby
82 lines
2.0 KiB
Ruby
class BillsController < ApplicationController
|
|
include CommentableForm
|
|
|
|
autocomplete :client, :name
|
|
|
|
before_action :set_bill, only: [:show, :edit, :update, :destroy]
|
|
before_action :authenticate_admin!
|
|
|
|
# GET /bills
|
|
# GET /bills.json
|
|
def index
|
|
@bills = Bill.all.order('paid ASC, due_date ASC')
|
|
end
|
|
|
|
# GET /bills/1
|
|
# GET /bills/1.json
|
|
def show
|
|
prepare_comment_for @bill
|
|
end
|
|
|
|
# GET /bills/new
|
|
def new
|
|
@bill = Bill.new
|
|
end
|
|
|
|
# GET /bills/1/edit
|
|
def edit
|
|
end
|
|
|
|
# POST /bills
|
|
# POST /bills.json
|
|
def create
|
|
@bill = Bill.new(bill_params)
|
|
|
|
respond_to do |format|
|
|
if @bill.save
|
|
format.html { redirect_to @bill, notice: 'Bill was successfully created.' }
|
|
format.json { render :show, status: :created, location: @bill }
|
|
else
|
|
format.html { render :new }
|
|
format.json { render json: @bill.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /bills/1
|
|
# PATCH/PUT /bills/1.json
|
|
def update
|
|
respond_to do |format|
|
|
if @bill.update(bill_params)
|
|
format.html { redirect_to @bill, notice: 'Bill was successfully updated.' }
|
|
format.json { render :show, status: :ok, location: @bill }
|
|
else
|
|
format.html { render :edit }
|
|
format.json { render json: @bill.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /bills/1
|
|
# DELETE /bills/1.json
|
|
def destroy
|
|
@bill.destroy
|
|
respond_to do |format|
|
|
format.html { redirect_to bills_url, notice: 'Bill was successfully destroyed.' }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_bill
|
|
@bill = Bill.find(params[:id])
|
|
end
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
def bill_params
|
|
params.require(:bill).permit(:client_id, :title, :description, :amount, :paid, :emission_date, :due_date)
|
|
end
|
|
|
|
end
|