budget/app/controllers/incomes_controller.rb
Andrew Tomaka fd75a7c6ff
All checks were successful
continuous-integration/drone/push Build is passing
Update and connect to drone (#1)
Reviewed-on: #1
2023-03-08 19:25:24 -05:00

71 lines
1.8 KiB
Ruby

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