2024-09-26 20:24:31 -07:00
|
|
|
class PetStatesController < ApplicationController
|
2024-09-27 22:14:00 -07:00
|
|
|
before_action :find_pet_state
|
2024-10-11 17:48:23 -07:00
|
|
|
before_action :support_staff_only
|
2024-09-27 22:14:00 -07:00
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @pet_state.update(pet_state_params)
|
|
|
|
flash[:notice] = "Pet appearance \##{@pet_state.id} successfully saved!"
|
2024-12-01 10:09:26 -08:00
|
|
|
redirect_to destination_after_save
|
2024-09-27 22:14:00 -07:00
|
|
|
else
|
|
|
|
render action: :edit, status: :bad_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def find_pet_state
|
2024-11-15 19:56:07 -08:00
|
|
|
@pet_type = PetType.find_by_param!(params[:pet_type_name])
|
2024-09-26 20:24:31 -07:00
|
|
|
@pet_state = @pet_type.pet_states.find(params[:id])
|
2024-12-01 10:28:58 -08:00
|
|
|
@reference_pet_type = @pet_type.reference
|
2024-09-26 20:24:31 -07:00
|
|
|
end
|
2024-09-27 22:14:00 -07:00
|
|
|
|
|
|
|
def pet_state_params
|
|
|
|
params.require(:pet_state).permit(:pose, :glitched)
|
|
|
|
end
|
2024-12-01 10:09:26 -08:00
|
|
|
|
|
|
|
def destination_after_save
|
|
|
|
if params[:next] == "unlabeled-appearance"
|
|
|
|
next_unlabeled_appearance_path
|
|
|
|
else
|
|
|
|
@pet_type
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_unlabeled_appearance_path
|
2024-12-01 11:13:21 -08:00
|
|
|
unlabeled_appearance = PetState.next_unlabeled_appearance
|
2024-12-01 10:09:26 -08:00
|
|
|
|
|
|
|
if unlabeled_appearance
|
|
|
|
edit_pet_type_pet_state_path(
|
|
|
|
unlabeled_appearance.pet_type,
|
|
|
|
unlabeled_appearance,
|
|
|
|
next: "unlabeled-appearance"
|
|
|
|
)
|
|
|
|
else
|
|
|
|
@pet_type
|
|
|
|
end
|
|
|
|
end
|
2024-09-26 20:24:31 -07:00
|
|
|
end
|