Method: Para::TagHelper#listing_for

Defined in:
app/helpers/para/tag_helper.rb

#listing_for(resources, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/para/tag_helper.rb', line 17

def listing_for(resources, options = {})
  model = resources.model
  attributes = model_field_mappings(model).fields
  relation = options.fetch(:relation, model.name.to_s.underscore.pluralize)
  allow_adding_resource = options.fetch(:addable, true)
  force_list = options.fetch(:force_list, false)

  partial = if !force_list && model.respond_to?(:roots) && can?(:tree, model)
    :tree
  else
    :list
  end

  render(
    partial: find_partial_for(relation, partial),
    locals: {
      component: @component,
      resources: resources,
      relation: relation,
      model: model,
      attributes: attributes,
      allow_adding_resource: allow_adding_resource
    }
  )
end