Custom fields
How this page is built
the gem renders it — this is all you write
User-defined properties that live outside the Book table (here in a property_values store) shown as extra columns. The model is untouched — the controller loads each PropertyDefinition and turns it into a CrudComponents::DynamicColumn, then passes the set as extra_columns: — to both crud_collection and the standalone crud_filter form. Each column carries a preload: (one query per page, no N+1), a typed filter: and a sort: — so Shelf (text), Weight (number range, in g), Signed (yes/no select) and Acquired (date range) filter with the control their type wants, not a plain text box. Try the inline filter row, the sort headers, and the sidebar form.
app/controllers/custom_fields_controller.rb
@books = Book.all
@columns = []
@columns << CrudComponents::DynamicColumn.new(
:price_usd,
label: 'Price (USD)',
as: :number,
unit: '$',
filter: ->(scope, geq:, leq:) { scope.where('price*1.1 >= ?', geq).where('price*1.1 <= ?', leq) },
sort: ->(scope, dir) { scope.order(Arel.sql("(price*1.1) #{dir}")) }
) { |record| record.price * 1.1 }
@columns += PropertyDefinition.order(:id).map { |defn| defn.to_crud_column(Book) }
app/models/property_definition.rb
def to_crud_column(subject_model)
definition = self
CrudComponents::DynamicColumn.new(
key.to_sym, label: label, as: renderer, unit: unit.presence,
preload: ->(records) { definition.values_by_subject(subject_model, records) }, # one query/page
filter: definition.filter_for(subject_model), # filters as the as: type (see below)
sort: ->(scope, dir) { definition.sort_scope(scope, subject_model, dir) }
) { |record, loaded| definition.cast(loaded[record.id]&.value) } # the value resolver
end
# Just a block — its control follows the column's as: flavor (number → range,
# date → range, boolean → yes/no, string → text):
def filter_for(subject_model)
case flavor
when 'number' then ->(s, geq:, leq:) { ... }
when 'boolean' then ->(s, eq:) { ... }
when 'date' then ->(s, geq:, leq:) { ... }
else ->(s, contains:) { ... }
end
end
app/views/custom_fields/index.html.erb
<%= crud_collection @books, fieldset: :compact, extra_columns: @columns %>
<%= crud_filter Book, fieldset: :compact, extra_columns: @columns %> <%# same dynamic columns in a standalone form %>
Read more: Dynamic columns · Views
| Title | Price | Price (USD) | Shelf | Weight | Signed | Acquired | ||
|---|---|---|---|---|---|---|---|---|
|
|
|
|
|
|
||||
| The Hidden Forest 1 | 28.24 € | 31.064 $ | A1 | 191.0 g | ✗ | 2022-07-15 | ||
| The Endless Mirror 2 | 28.63 € | 31.493 $ | B1 | 462.0 g | ✗ | 2022-12-26 | ||
| The Ancient Winter 3 | 24.81 € | 27.291 $ | C2 | 276.0 g | ✓ | 2025-04-30 | ||
| The Dispossessed City 4 | 19.95 € | 21.945 $ | B2 | 248.0 g | ✗ | 2024-06-15 | ||
| The Quiet Mirror 5 | 32.73 € | 36.003 $ | B1 | 212.0 g | ✗ | 2026-10-01 | ||
| The Burning Winter 6 | 21.78 € | 23.958 $ | A1 | 198.0 g | ✗ | 2026-05-07 | ||
| The Dispossessed City 7 | 17.82 € | 19.602 $ | B1 | 629.0 g | ✗ | 2025-05-10 | ||
| The Quiet Forest 8 | 11.98 € | 13.178 $ | Reserve | 631.0 g | ✓ | 2023-09-12 | ||
| The Broken Engine 9 | 32.99 € | 36.289 $ | B2 | 873.0 g | ✓ | 2022-06-19 | ||
| The Distant City 10 | 26.91 € | 29.601 $ | Reserve | 705.0 g | ✓ | 2022-12-24 | ||
| The Endless Station 11 | 10.86 € | 11.946 $ | C2 | 656.0 g | ✗ | 2025-10-12 | ||
| The Dispossessed Station 12 | 16.58 € | 18.238 $ | C1 | 517.0 g | ✓ | 2024-12-06 | ||
| The Endless Station 13 | 27.05 € | 29.755 $ | A1 | 748.0 g | ✗ | 2026-04-16 | ||
| The Hidden Mirror 14 | 22.58 € | 24.838 $ | C2 | 848.0 g | ✗ | 2026-11-03 | ||
| The Endless Forest 15 | 11.84 € | 13.024 $ | A2 | 697.0 g | ✗ | 2023-03-12 | ||
| The Ancient Signal 16 | 35.51 € | 39.061 $ | B2 | 497.0 g | ✓ | 2021-06-10 | ||
| The Endless Dune 17 | 18.69 € | 20.559 $ | A2 | 653.0 g | ✗ | 2025-09-21 | ||
| The Quiet Door 18 | 21.79 € | 23.969 $ | A1 | 910.0 g | ✓ | 2023-07-11 | ||
| The Hidden Mirror 19 | 37.51 € | 41.261 $ | Reserve | 566.0 g | ✗ | 2026-08-14 | ||
| The Burning Tower 20 | 14.56 € | 16.016 $ | A1 | 387.0 g | ✗ | 2022-05-05 | ||
| The Endless City 21 | 36.46 € | 40.106 $ | A2 | 345.0 g | ✗ | 2026-06-19 | ||
| The Hidden Archive 22 | 23.21 € | 25.531 $ | B1 | 618.0 g | ✓ | 2026-04-15 | ||
| The Hidden Engine 23 | 40.55 € | 44.605 $ | C1 | 674.0 g | ✗ | 2026-10-31 | ||
| The Ancient Mirror 24 | 33.42 € | 36.762 $ | B1 | 732.0 g | ✗ | 2026-06-25 | ||
| The Endless Winter 25 | 41.02 € | 45.122 $ | B2 | 582.0 g | ✗ | 2022-10-05 | ||
| The Distant Door 26 | 16.40 € | 18.04 $ | Reserve | 593.0 g | ✓ | 2024-09-09 | ||
| The Quiet City 27 | 39.79 € | 43.769 $ | C2 | 313.0 g | ✓ | 2023-04-23 | ||
| The Endless Winter 28 | 29.97 € | 32.967 $ | A2 | 252.0 g | ✓ | 2023-02-13 | ||
| The Dispossessed Winter 29 | 9.04 € | 9.944 $ | C2 | 924.0 g | ✓ | 2026-08-12 | ||
| The Endless Winter 30 | 39.19 € | 43.109 $ | B1 | 687.0 g | ✗ | 2025-10-03 | ||
| The Hidden Engine 31 | 32.85 € | 36.135 $ | B2 | 244.0 g | ✓ | 2023-08-30 | ||
| The Hidden Winter 32 | 40.79 € | 44.869 $ | A1 | 445.0 g | ✓ | 2023-11-13 | ||
| The Endless Signal 33 | 39.74 € | 43.714 $ | B1 | 841.0 g | ✓ | 2025-05-09 | ||
| The Distant Garden 34 | 25.55 € | 28.105 $ | C1 | 427.0 g | ✗ | 2024-07-05 | ||
| The Endless Door 35 | 24.06 € | 26.466 $ | A2 | 593.0 g | ✓ | 2026-02-09 | ||
| The Burning Door 36 | 31.42 € | 34.562 $ | A1 | 480.0 g | ✗ | 2024-01-24 | ||
| The Broken Mirror 37 | 7.28 € | 8.008 $ | A1 | 316.0 g | ✗ | 2026-08-29 | ||
| The Distant Forest 38 | 38.71 € | 42.581 $ | A1 | 829.0 g | ✗ | 2023-11-19 | ||
| The Silent Tower 39 | 25.60 € | 28.16 $ | C1 | 225.0 g | ✗ | 2024-05-06 | ||
| The Silent Archive 40 | 41.43 € | 45.573 $ | C2 | 355.0 g | ✗ | 2025-02-01 | ||
| The Luminous Machine 41 | 23.63 € | 25.993 $ | A2 | 549.0 g | ✓ | 2026-09-27 | ||
| The Ancient Garden 42 | 35.86 € | 39.446 $ | A2 | 598.0 g | ✗ | 2022-09-11 | ||
| The Ancient Garden 43 | 42.67 € | 46.937 $ | C1 | 306.0 g | ✓ | 2021-07-21 | ||
| The Hidden Station 44 | 12.11 € | 13.321 $ | Reserve | 450.0 g | ✗ | 2022-06-05 | ||
| The Luminous City 45 | 19.30 € | 21.23 $ | B1 | 252.0 g | ✓ | 2021-07-23 | ||
| The Distant Engine 46 | 21.25 € | 23.375 $ | B1 | 427.0 g | ✗ | 2021-12-07 | ||
| The Hidden Tower 47 | 19.92 € | 21.912 $ | B1 | 556.0 g | ✓ | 2026-06-03 | ||
| The Broken Empire 48 | 30.49 € | 33.539 $ | A2 | 391.0 g | ✓ | 2022-03-22 | ||
| The Broken Dune 49 | 22.90 € | 25.19 $ | Reserve | 548.0 g | ✓ | 2026-06-22 | ||
| The Burning Station 50 | 14.43 € | 15.873 $ | Reserve | 659.0 g | ✗ | 2023-12-15 | ||
| The Ancient Machine 51 | 40.77 € | 44.847 $ | Reserve | 916.0 g | ✓ | 2023-01-30 | ||
| The Distant Garden 52 | 36.80 € | 40.48 $ | C1 | 478.0 g | ✗ | 2024-09-09 | ||
| The Ancient Ocean 53 | 25.74 € | 28.314 $ | B1 | 240.0 g | ✗ | 2024-04-01 | ||
| The Dispossessed Empire 54 | 43.50 € | 47.85 $ | C2 | 493.0 g | ✓ | 2025-12-24 | ||
| The Endless Station 55 | 20.24 € | 22.264 $ | A2 | 785.0 g | ✗ | 2022-09-15 | ||
| The Ancient Forest 56 | 33.64 € | 37.004 $ | A2 | 517.0 g | ✗ | 2025-02-19 | ||
| The Luminous City 57 | 23.17 € | 25.487 $ | B1 | 343.0 g | ✓ | 2026-01-05 | ||
| The Broken Empire 58 | 34.83 € | 38.313 $ | C1 | 683.0 g | ✗ | 2025-10-29 | ||
| The Quiet Empire 59 | 39.87 € | 43.857 $ | A2 | 782.0 g | ✗ | 2021-12-16 | ||
| The Silent Station 60 | 34.96 € | 38.456 $ | B1 | 673.0 g | ✗ | 2024-11-29 | ||
| The Broken Station 61 | 18.89 € | 20.779 $ | A1 | 688.0 g | ✗ | 2022-05-22 | ||
| The Quiet Dune 62 | 24.14 € | 26.554 $ | A1 | 474.0 g | ✓ | 2021-06-19 | ||
| The Distant Tower 63 | 18.55 € | 20.405 $ | B2 | 873.0 g | ✓ | 2025-02-09 | ||
| The Dispossessed Forest 64 | 36.11 € | 39.721 $ | A2 | 747.0 g | ✓ | 2024-07-20 | ||
| The Hidden Ocean 65 | 43.18 € | 47.498 $ | A2 | 624.0 g | ✗ | 2025-11-22 | ||
| The Dispossessed City 66 | 29.12 € | 32.032 $ | B1 | 367.0 g | ✗ | 2025-01-09 | ||
| The Ancient Dune 67 | 38.41 € | 42.251 $ | B2 | 805.0 g | ✗ | 2022-05-22 | ||
| The Luminous Forest 68 | 40.60 € | 44.66 $ | C1 | 514.0 g | ✗ | 2022-08-19 | ||
| The Endless City 69 | 40.98 € | 45.078 $ | A2 | 242.0 g | ✗ | 2025-06-26 | ||
| The Silent Station 70 | 34.46 € | 37.906 $ | B1 | 877.0 g | ✓ | 2023-07-10 | ||
| The Ancient Engine 71 | 32.68 € | 35.948 $ | B2 | 393.0 g | ✗ | 2026-07-08 | ||
| The Distant Dune 72 | 32.20 € | 35.42 $ | C1 | 267.0 g | ✗ | 2024-03-07 | ||
| The Endless Signal 73 | 19.39 € | 21.329 $ | Reserve | 308.0 g | ✓ | 2024-01-28 | ||
| The Ancient Ocean 74 | 14.70 € | 16.17 $ | C2 | 933.0 g | ✓ | 2023-01-11 | ||
| The Hidden Tower 75 | 5.34 € | 5.874 $ | C2 | 217.0 g | ✓ | 2024-02-16 | ||
| The Luminous Engine 76 | 34.79 € | 38.269 $ | C1 | 824.0 g | ✓ | 2024-12-06 | ||
| The Luminous Tower 77 | 28.81 € | 31.691 $ | B2 | 200.0 g | ✗ | 2025-08-22 | ||
| The Hidden Engine 78 | 8.00 € | 8.8 $ | B1 | 800.0 g | ✓ | 2022-06-14 | ||
| The Hidden Dune 79 | 24.25 € | 26.675 $ | B1 | 248.0 g | ✓ | 2026-05-08 | ||
| The Ancient Engine 80 | 17.29 € | 19.019 $ | B2 | 623.0 g | ✓ | 2026-01-12 | ||
| The Burning Forest 81 | 6.28 € | 6.908 $ | A2 | 714.0 g | ✓ | 2026-02-16 | ||
| The Dispossessed Archive 82 | 35.72 € | 39.292 $ | C1 | 498.0 g | ✗ | 2026-09-29 | ||
| The Distant Engine 83 | 39.52 € | 43.472 $ | A1 | 928.0 g | ✓ | 2021-11-08 | ||
| The Luminous Mirror 84 | 19.40 € | 21.34 $ | Reserve | 568.0 g | ✗ | 2025-03-08 | ||
| The Luminous City 85 | 22.63 € | 24.893 $ | A2 | 356.0 g | ✗ | 2026-01-10 | ||
| The Distant Station 86 | 12.86 € | 14.146 $ | Reserve | 276.0 g | ✓ | 2023-07-02 | ||
| The Quiet Door 87 | 35.06 € | 38.566 $ | C1 | 316.0 g | ✗ | 2024-02-13 | ||
| The Luminous Tower 88 | 37.25 € | 40.975 $ | C1 | 726.0 g | ✓ | 2025-01-27 | ||
| The Dispossessed Empire 89 | 11.61 € | 12.771 $ | A1 | 809.0 g | ✓ | 2022-12-01 | ||
| The Quiet Tower 90 | 31.01 € | 34.111 $ | Reserve | 644.0 g | ✗ | 2025-08-06 | ||
| The Hidden Tower 91 | 29.28 € | 32.208 $ | B1 | 593.0 g | ✓ | 2024-06-08 | ||
| The Hidden Winter 92 | 29.93 € | 32.923 $ | C2 | 636.0 g | ✓ | 2023-06-06 | ||
| The Ancient Forest 93 | 41.21 € | 45.331 $ | C1 | 778.0 g | ✓ | 2025-01-17 | ||
| The Luminous Station 94 | 26.90 € | 29.59 $ | C2 | 551.0 g | ✓ | 2022-05-17 | ||
| The Quiet Station 95 | 6.29 € | 6.919 $ | Reserve | 224.0 g | ✓ | 2023-05-29 | ||
| The Distant Winter 96 | 10.36 € | 11.396 $ | C1 | 629.0 g | ✓ | 2025-02-12 | ||
| The Endless Engine 97 | 43.50 € | 47.85 $ | B2 | 197.0 g | ✗ | 2025-01-27 | ||
| The Endless Mirror 98 | 33.32 € | 36.652 $ | C2 | 468.0 g | ✗ | 2024-11-29 | ||
| The Hidden Garden 99 | 24.11 € | 26.521 $ | C2 | 414.0 g | ✗ | 2024-04-26 | ||
| The Burning Archive 100 | 24.48 € | 26.928 $ | B1 | 813.0 g | ✗ | 2024-02-04 | ||
| The Dispossessed Ocean 101 | 12.58 € | 13.838 $ | B1 | 853.0 g | ✓ | 2023-06-11 | ||
| The Broken City 102 | 40.54 € | 44.594 $ | B2 | 190.0 g | ✗ | 2022-03-23 | ||
| The Dispossessed Door 103 | 30.10 € | 33.11 $ | Reserve | 738.0 g | ✗ | 2023-09-26 | ||
| The Broken Forest 104 | 17.49 € | 19.239 $ | B1 | 297.0 g | ✓ | 2023-01-14 | ||
| The Endless Ocean 105 | 34.90 € | 38.39 $ | B2 | 843.0 g | ✗ | 2025-11-22 | ||
| The Hidden Door 106 | 19.30 € | 21.23 $ | C1 | 316.0 g | ✓ | 2023-04-17 | ||
| The Hidden Door 107 | 17.84 € | 19.624 $ | C2 | 660.0 g | ✓ | 2026-05-09 | ||
| The Luminous Ocean 108 | 39.89 € | 43.879 $ | A2 | 354.0 g | ✗ | 2025-08-28 | ||
| The Hidden Garden 109 | 22.95 € | 25.245 $ | C1 | 533.0 g | ✓ | 2026-07-02 | ||
| The Burning Station 110 | 24.38 € | 26.818 $ | C2 | 272.0 g | ✗ | 2026-03-26 | ||
| The Distant Archive 111 | 11.59 € | 12.749 $ | C1 | 739.0 g | ✓ | 2026-03-20 | ||
| The Dispossessed Signal 112 | 38.73 € | 42.603 $ | C1 | 474.0 g | ✗ | 2024-07-17 | ||
| The Quiet Forest 113 | 33.56 € | 36.916 $ | A2 | 196.0 g | ✓ | 2023-05-07 | ||
| The Ancient Archive 114 | 44.21 € | 48.631 $ | C1 | 484.0 g | ✓ | 2024-01-24 | ||
| The Silent Engine 115 | 24.38 € | 26.818 $ | A2 | 282.0 g | ✓ | 2026-05-11 | ||
| The Silent Archive 116 | 10.28 € | 11.308 $ | A1 | 753.0 g | ✓ | 2026-06-02 | ||
| The Endless Empire 117 | 29.30 € | 32.23 $ | A1 | 430.0 g | ✓ | 2023-01-09 | ||
| The Burning Empire 118 | 17.01 € | 18.711 $ | Reserve | 720.0 g | ✓ | 2025-09-30 | ||
| The Ancient Archive 119 | 21.49 € | 23.639 $ | A2 | 559.0 g | ✗ | 2026-10-26 | ||
| The Silent Station 120 | 42.11 € | 46.321 $ | C2 | 847.0 g | ✓ | 2025-02-26 | ||