class BubblesController < ApplicationController before_action :authenticate_user! def index @bubbles = Bubble.all end def new @bubble = Bubble.new end def show @bubble = Bubble.find(params[:id]) @spendings = @bubble.spendings.unscope(:order).order(created_at: :desc) 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 params.require(:bubble).permit(:name, :description, :color, :owner_id) end end