tabletop-companion/app/controllers/tables_controller.rb

62 lines
1.2 KiB
Ruby
Raw Normal View History

2024-05-26 10:45:10 +00:00
# frozen_string_literal: true
2024-05-26 08:36:07 +00:00
class TablesController < ApplicationController
2024-05-28 19:16:43 +00:00
before_action :set_table, only: [ :show, :edit, :update, :destroy ]
2024-05-26 08:36:07 +00:00
def index
2024-05-28 19:16:43 +00:00
@tables = Current.user.tables
end
def show
end
def new
@table = Table.new
end
def create
@table = Current.user.tables.new(table_params)
@table.slug = helpers.generate_slug_for(model: Table, string: @table.name)
if @table.save
redirect_to @table, notice: t(".success", name: @table.name)
else
flash.now[:alert] = t(".error")
render :new, status: :unprocessable_entity
end
end
def edit
end
def update
if @table.update(table_params)
redirect_to @table, notice: t(".success", name: @table.name)
else
flash.now[:alert] = t(".error")
render :edit, status: :unprocessable_entity
end
end
def destroy
if @table.destroy
redirect_to tables_path, notice: t(".success", name: @table.name)
else
flash[:alert] = t(".error", name: @table.name)
redirect_to tables_path
end
2024-05-26 08:36:07 +00:00
end
2024-05-28 19:16:43 +00:00
private
def set_table
@table = Current.user.tables.find(params[:id])
end
def table_params
params.require(:table).permit(
:name,
:game_system_id,
)
end
2024-05-26 08:36:07 +00:00
end