62 lines
1.2 KiB
Ruby
62 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class TablesController < ApplicationController
|
|
before_action :set_table, only: [ :show, :edit, :update, :destroy ]
|
|
|
|
def index
|
|
@tables = Current.user.tables
|
|
end
|
|
|
|
def show
|
|
@table_invites = @table.table_invites.not_responded
|
|
end
|
|
|
|
def new
|
|
@table = Table.new
|
|
end
|
|
|
|
def create
|
|
@table = Current.user.owned_tables.new(table_params)
|
|
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
|
|
end
|
|
|
|
private
|
|
|
|
def set_table
|
|
@table = Current.user.tables.find(params[:id])
|
|
end
|
|
|
|
def table_params
|
|
params.require(:table).permit(
|
|
:name,
|
|
:game_system_id,
|
|
)
|
|
end
|
|
end
|