budget/app/controllers/extra_bills_controller.rb

70 lines
2 KiB
Ruby

class ExtraBillsController < ApplicationController
before_action :set_extra_bill, only: %i[ show edit update destroy ]
# GET /extra_bills or /extra_bills.json
def index
@extra_bills = ExtraBill.all
end
# GET /extra_bills/1 or /extra_bills/1.json
def show
end
# GET /extra_bills/new
def new
@extra_bill = ExtraBill.new
end
# GET /extra_bills/1/edit
def edit
end
# POST /extra_bills or /extra_bills.json
def create
@extra_bill = ExtraBill.new(extra_bill_params)
respond_to do |format|
if @extra_bill.save
format.html { redirect_to extra_bill_url(@extra_bill), notice: "Extra bill was successfully created." }
format.json { render :show, status: :created, location: @extra_bill }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @extra_bill.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /extra_bills/1 or /extra_bills/1.json
def update
respond_to do |format|
if @extra_bill.update(extra_bill_params)
format.html { redirect_to extra_bill_url(@extra_bill), notice: "Extra bill was successfully updated." }
format.json { render :show, status: :ok, location: @extra_bill }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @extra_bill.errors, status: :unprocessable_entity }
end
end
end
# DELETE /extra_bills/1 or /extra_bills/1.json
def destroy
@extra_bill.destroy
respond_to do |format|
format.html { redirect_to extra_bills_url, notice: "Extra bill was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_extra_bill
@extra_bill = ExtraBill.find(params[:id])
end
# Only allow a list of trusted parameters through.
def extra_bill_params
params.require(:extra_bill).permit(:description, :amount, :deduct_autopaid)
end
end