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-30 16:08:51 +00:00
|
|
|
@tables = Current.user.tables
|
2024-05-28 19:16:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2024-05-29 15:47:31 +00:00
|
|
|
@table_invites = @table.table_invites.not_responded
|
2024-05-28 19:16:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@table = Table.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2024-05-29 08:09:58 +00:00
|
|
|
@table = Current.user.owned_tables.new(table_params)
|
2024-05-28 19:16:43 +00:00
|
|
|
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
|