076a30a37f
Always place them at the top. Our current search support in SQLite is based on standalone fields. We should add a field for IDs and make it work with prefixes. Going with something simpler for now. https://3.basecamp.com/2914079/buckets/37331921/todos/8773497815#__recording_8775856927
31 lines
659 B
Ruby
31 lines
659 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
|
|
|
|
render layout: false
|
|
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
|