Files
fizzy/app/controllers/bubbles_controller.rb
T
2024-09-24 15:32:44 -04:00

47 lines
1.1 KiB
Ruby

class BubblesController < ApplicationController
include BucketScoped
before_action :set_bubble, only: %i[ show edit update ]
def index
if params[:tag_id]
@tag = Tag.find(params[:tag_id])
@bubbles = @tag.bubbles
@most_active_bubbles = @tag.bubbles.left_joins(:comments, :boosts).group(:id).order(Arel.sql("COUNT(comments.id) + COUNT(boosts.id) DESC")).limit(10)
else
@bubbles = @bucket.bubbles.order(created_at: :desc)
@most_active_bubbles = @bucket.bubbles.left_joins(:comments, :boosts).group(:id).order(Arel.sql("COUNT(comments.id) + COUNT(boosts.id) DESC")).limit(10)
end
end
def new
@bubble = @bucket.bubbles.build
end
def create
@bubble = @bucket.bubbles.create!(bubble_params)
redirect_to bucket_bubble_url(@bucket, @bubble)
end
def show
end
def edit
end
def update
@bubble.update!(bubble_params)
redirect_to bucket_bubble_url(@bucket, @bubble)
end
private
def set_bubble
@bubble = @bucket.bubbles.find(params[:id])
end
def bubble_params
params.require(:bubble).permit(:title, :color, :due_on, :image, tag_ids: [])
end
end