52 lines
1.2 KiB
Ruby
52 lines
1.2 KiB
Ruby
class CountController < ApplicationController
|
|
before_action :authenticate_user!
|
|
|
|
def index
|
|
@counts = Total.all
|
|
end
|
|
|
|
def edit
|
|
@count = Total.find(params[:id])
|
|
end
|
|
|
|
def destroy
|
|
if Total.find(params[:id]).destroy
|
|
flash[:notice] = I18n.translate("flashes.count.destroy.success")
|
|
redirect_to count_index_path
|
|
else
|
|
flash[:alert] = I18n.translate("flashes.count.destroy.fail")
|
|
redirect_to edit_count_path
|
|
end
|
|
end
|
|
|
|
def new
|
|
@count = Total.new
|
|
end
|
|
|
|
def update
|
|
if Total.find(params[:id]).update(validated_params(params))
|
|
flash[:notice] = I18n.translate("flashes.count.update.success")
|
|
redirect_to count_index_path
|
|
else
|
|
flash[:alert] = I18n.translate("flashes.count.update.fail")
|
|
redirect_to edit_count_path
|
|
end
|
|
end
|
|
|
|
def create
|
|
if Total.new(validated_params(params)).save
|
|
flash[:notice] = I18n.translate("flashes.count.create.success")
|
|
redirect_to count_index_path
|
|
else
|
|
flash[:alert] = I18n.translate("flashes.count.create.fail")
|
|
redirect_to new_count_path
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def validated_params(params)
|
|
params.require(:total).permit([:name, :count])
|
|
end
|
|
end
|