Module: NitroRails::ResourceCollectionHelper

Defined in:
app/helpers/nitro_rails/resource_collection_helper.rb

Instance Method Summary collapse

Instance Method Details

#resource_collection(*resources_or_path, **options, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/nitro_rails/resource_collection_helper.rb', line 3

def resource_collection(*resources_or_path, **options, &block)
  # signature = source_stamp.hash.abs.to_s(36)

  if resources_or_path.last.is_a?(Symbol) 
    resources_method = resources_or_path[-1]
    resources_type = resources_method.to_s.singularize
    resources_parent = resources_or_path[-2]
    # resources_parent_type = resources_parent.type
    resources_path = [resources_parent, resources_method]
    resources = resources_parent.send(resources_method).where(options[:where])
  else 
    resources_type = resources_or_path.first.table.name.singularize
    resources = resources_or_path.first
  end
  
  
  # binding.pry
  ResourceCollection.new(resources, view: self, create_path: resources_path, parent: resources_parent, resource_type: resources_type, id: block.to_s.hash).render_content(&block)
end