Skip to content

Trek::Keyable

Batch lookup of records by their key attribute, preserving the requested order.

Methods

MethodReturns
Model.take_by_keys(keys)the records matching keys, in the same order, with nil for missing keys

Usage

ruby
Page.take_by_keys(%w[services about missing])
# => [#<Page key="services">, #<Page key="about">, nil]

Handy for rendering a fixed set of pages or fragments in a specific order in your views.

Released under the MIT License.