2024-04-04 17:29:50 -04:00
|
|
|
class Transactions::CategoriesController < ApplicationController
|
|
|
|
before_action :set_category, only: [ :update, :destroy ]
|
|
|
|
|
2024-04-18 07:56:51 -04:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
2024-04-04 17:29:50 -04:00
|
|
|
def create
|
|
|
|
if Current.family.transaction_categories.create(category_params)
|
|
|
|
redirect_to transactions_path, notice: t(".success")
|
|
|
|
else
|
|
|
|
render transactions_path, status: :unprocessable_entity, notice: t(".error")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @category.update(category_params)
|
|
|
|
redirect_to transactions_path, notice: t(".success")
|
|
|
|
else
|
|
|
|
render transactions_path, status: :unprocessable_entity, notice: t(".error")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@category.destroy!
|
|
|
|
redirect_to transactions_path, notice: t(".success")
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_category
|
|
|
|
@category = Current.family.transaction_categories.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def category_params
|
2024-04-29 21:17:28 +02:00
|
|
|
params.require(:transaction_category).permit(:name, :color)
|
2024-04-04 17:29:50 -04:00
|
|
|
end
|
|
|
|
end
|