Files
fizzy/app/controllers/prompts/cards_controller.rb
T
Jorge Manrubia 7286d03f57 Format
2025-06-20 11:35:23 +02:00

33 lines
696 B
Ruby

class Prompts::CardsController < ApplicationController
MAX_RESULTS = 10
def index
@cards = if filter_param.present?
prepending_exact_matches_by_id(published_cards.mentioning(params[:filter]))
else
@cards = published_cards.latest
end
if stale? etag: @cards
render layout: false
end
end
private
def filter_param
params[:filter]
end
def published_cards
Current.user.accessible_cards.published.limit(MAX_RESULTS)
end
def prepending_exact_matches_by_id(cards)
if card_by_id = Current.user.accessible_cards.find_by_id(params[:filter])
[ card_by_id ] + cards
else
cards
end
end
end