Method: Datagrid::Helper#datagrid_form_with

Defined in:
lib/datagrid/helper.rb

#datagrid_form_with(**options) ⇒ String

Renders HTML for grid with all filters inputs and labels defined in it

Parameters:

  • options (Hash{Symbol => Object})

Options Hash (**options):

  • partials (String)

    Path for form partial lookup. Default: 'datagrid', which uses app/views/datagrid/ partials. Example: 'datagrid_admin' uses app/views/datagrid_admin partials.

  • model (Datagrid::Base)

    a Datagrid object to be rendered.

  • All (Hash)

    options supported by Rails form_with helper.

Returns:

  • (String)

    form HTML tag markup

Raises:


369
370
371
372
373
374
375
376
# File 'lib/datagrid/helper.rb', line 369

def datagrid_form_with(**options)
  raise ArgumentError, "datagrid_form_with block argument is invalid. Use form_with instead." if block_given?

  grid = options[:model]
  raise ArgumentError, "Grid has no available filters" if grid&.filters&.empty?

  _render_partial("form", options[:partials], { grid: options[:model], options: options })
end