2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-15 15:40:40 -04:00
|
|
|
class MascotsController < ApplicationController
|
|
|
|
respond_to :html, :json
|
|
|
|
before_action :admin_only, except: [:index]
|
|
|
|
|
|
|
|
def index
|
2024-04-04 16:52:49 -04:00
|
|
|
@mascots = Mascot.search(search_params).paginate(params[:page], limit: params[:limit])
|
2022-10-15 15:40:40 -04:00
|
|
|
respond_with(@mascots)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@mascot = Mascot.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@mascot = Mascot.create(mascot_params.merge(creator: CurrentUser.user))
|
|
|
|
ModAction.log(:mascot_create, { id: @mascot.id }) if @mascot.valid?
|
|
|
|
respond_with(@mascot, location: mascots_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@mascot = Mascot.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@mascot = Mascot.find(params[:id])
|
|
|
|
@mascot.update(mascot_params)
|
|
|
|
ModAction.log(:mascot_update, { id: @mascot.id }) if @mascot.valid?
|
|
|
|
respond_with(@mascot, location: mascots_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@mascot = Mascot.find(params[:id])
|
|
|
|
@mascot.destroy
|
|
|
|
ModAction.log(:mascot_delete, { id: @mascot.id })
|
|
|
|
respond_with(@mascot)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def mascot_params
|
2023-02-03 12:11:17 -05:00
|
|
|
params.fetch(:mascot, {}).permit(%i[mascot_file display_name background_color artist_url artist_name available_on_string active])
|
2022-10-15 15:40:40 -04:00
|
|
|
end
|
|
|
|
end
|