2023-11-01 20:54:06 +01:00
|
|
|
class BubblesController < ApplicationController
|
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
|
|
def index
|
|
|
|
@bubbles = Bubble.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@bubble = Bubble.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
if Bubble.new(allowed_params).save
|
|
|
|
redirect_to bubbles_path, flash: { success: "Créé" }
|
|
|
|
else
|
|
|
|
redirect_to new_bubble_path, flash: { error: "Pas créé" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@bubble = Bubble.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@bubble = Bubble.find(params[:id])
|
|
|
|
if @bubble.update(allowed_params)
|
|
|
|
redirect_to bubbles_path, flash: { success: "Sauvegardé" }
|
|
|
|
else
|
|
|
|
redirect_to edit_bubble_path(@bubble), flash: { error: "Pas sauvegardé" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_destroy
|
|
|
|
@bubble = Bubble.find(params[:bubble_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@bubble = Bubble.find(params[:id])
|
|
|
|
if @bubble.destroy
|
|
|
|
redirect_to bubbles_path, flash: { success: "Supprimé" }
|
|
|
|
else
|
|
|
|
redirect_to bubbles_path, flash: { error: "Pas supprimé" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def allowed_params
|
2023-12-31 18:11:17 +01:00
|
|
|
params.require(:bubble).permit(:name, :description, :color, :owner_id)
|
2023-11-01 20:54:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|