Files
fizzy/app/controllers/cards_controller.rb
T
Mike Dalessio b05ecb7809 Update card buttons dynamically
User flows when editing a card look like:
- Click "Edit" → the closure buttons are replaced by "Save changes"
- Submit card form → Saves and restores closure buttons
- Press ESC while editing → Cancels and restores closure buttons

Also, renamed for clarity:
- _title.html.erb → _content.html.erb

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 12:14:39 -05:00

49 lines
1.0 KiB
Ruby

class CardsController < ApplicationController
include FilterScoped
before_action :set_board, only: %i[ create ]
before_action :set_card, only: %i[ show edit update destroy ]
before_action :ensure_permission_to_administer_card, only: %i[ destroy ]
def index
set_page_and_extract_portion_from @filter.cards
end
def create
card = @board.cards.find_or_create_by!(creator: Current.user, status: "drafted")
redirect_to card
end
def show
end
def edit
end
def update
@card.update! card_params
end
def destroy
@card.destroy!
redirect_to @card.board, notice: "Card deleted"
end
private
def set_board
@board = Current.user.boards.find params[:board_id]
end
def set_card
@card = Current.user.accessible_cards.find_by!(number: params[:id])
end
def ensure_permission_to_administer_card
head :forbidden unless Current.user.can_administer_card?(@card)
end
def card_params
params.expect(card: [ :status, :title, :description, :image, tag_ids: [] ])
end
end