2024-06-20 08:38:59 -04:00
|
|
|
class MerchantsController < ApplicationController
|
2024-07-26 18:00:41 +02:00
|
|
|
layout :with_sidebar
|
2024-06-20 08:38:59 -04:00
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@merchant = Merchant.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
Current.family.merchants.create!(merchant_params)
|
|
|
|
redirect_to merchants_path, notice: t(".success")
|
|
|
|
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
|