Files
fizzy/app/controllers/cards/pins_controller.rb
T
David Heinemeier Hansson f3000a02c5 Follow render_card_replacement pattern
And clean up the rest of the implementation a tad.
2025-04-18 15:20:38 +02:00

34 lines
765 B
Ruby

class Cards::PinsController < ApplicationController
include CardScoped
def show
end
def create
@pin = @card.pin_by Current.user
broadcast_add_pin_to_tray
render_pin_button_replacement
end
def destroy
@pin = @card.unpin_by Current.user
broadcast_remove_pin_from_tray
render_pin_button_replacement
end
private
def broadcast_add_pin_to_tray
@pin.broadcast_prepend_to [ Current.user, :pins_tray ], target: "pins", partial: "my/pins/pin"
end
def broadcast_remove_pin_from_tray
@pin.broadcast_remove_to [ Current.user, :pins_tray ]
end
def render_pin_button_replacement
turbo_stream.replace [ @card, :pin_button ], partial: "cards/pins/pin_button", locals: { card: @card }
end
end