Class: CrudComponents::Presenters::CellContext
- Inherits:
-
Object
- Object
- CrudComponents::Presenters::CellContext
- Defined in:
- lib/crud_components/presenters/cell_context.rb
Overview
Passed to value renderers so a cell can offer click-to-filter (enum badges, boolean icons) — respecting the active query’s fieldset whitelist and param_prefix. Nil on surfaces without a query (the record page, static collections), so renderers must null-check it.
Instance Method Summary collapse
-
#filter_url(field, value) ⇒ Object
A URL that adds (or replaces) this field’s filter, keeping every other active param — prefixed correctly for multi-collection pages.
-
#filterable?(field) ⇒ Boolean
Is this field one the current query would actually act on?.
-
#initialize(view:, query:) ⇒ CellContext
constructor
A new instance of CellContext.
Constructor Details
#initialize(view:, query:) ⇒ CellContext
Returns a new instance of CellContext.
8 9 10 11 |
# File 'lib/crud_components/presenters/cell_context.rb', line 8 def initialize(view:, query:) @view = view @query = query end |
Instance Method Details
#filter_url(field, value) ⇒ Object
A URL that adds (or replaces) this field’s filter, keeping every other active param — prefixed correctly for multi-collection pages.
20 21 22 23 24 25 |
# File 'lib/crud_components/presenters/cell_context.rb', line 20 def filter_url(field, value) params = @view.request.query_parameters.merge( @query.param_name(field.name.to_s) => value.to_s ) "#{@view.request.path}?#{params.to_query}" end |
#filterable?(field) ⇒ Boolean
Is this field one the current query would actually act on?
14 15 16 |
# File 'lib/crud_components/presenters/cell_context.rb', line 14 def filterable?(field) @query.filter_fields.include?(field) end |