2024-06-20 08:38:59 -04:00
|
|
|
class MerchantsController < ApplicationController
|
2024-08-23 10:06:24 -04:00
|
|
|
before_action :set_merchant, only: %i[edit update destroy]
|
2024-06-20 08:38:59 -04:00
|
|
|
|
|
|
|
def index
|
|
|
|
@merchants = Current.family.merchants.alphabetically
|
2025-02-21 11:57:59 -05:00
|
|
|
|
|
|
|
render layout: "settings"
|
2024-06-20 08:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@merchant = Merchant.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2024-10-24 11:02:27 -04:00
|
|
|
@merchant = Current.family.merchants.new(merchant_params)
|
|
|
|
|
|
|
|
if @merchant.save
|
|
|
|
redirect_to merchants_path, notice: t(".success")
|
|
|
|
else
|
|
|
|
redirect_to merchants_path, alert: t(".error", error: @merchant.errors.full_messages.to_sentence)
|
|
|
|
end
|
2024-06-20 08:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@merchant.update!(merchant_params)
|
|
|
|
redirect_to merchants_path, notice: t(".success")
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@merchant.destroy!
|
|
|
|
redirect_to merchants_path, notice: t(".success")
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-08-23 10:06:24 -04:00
|
|
|
def set_merchant
|
|
|
|
@merchant = Current.family.merchants.find(params[:id])
|
|
|
|
end
|
2024-06-20 08:38:59 -04:00
|
|
|
|
2024-08-23 10:06:24 -04:00
|
|
|
def merchant_params
|
|
|
|
params.require(:merchant).permit(:name, :color)
|
|
|
|
end
|
2024-06-20 08:38:59 -04:00
|
|
|
end
|