Class: Views::Resources::Show

Inherits:
Base
  • Object
show all
Defined in:
app/views/resources/show.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.has_many(name, &config) ⇒ Object



8
9
10
# File 'app/views/resources/show.rb', line 8

def self.has_many(name, &config)
  has_manys[name] = Views::Resources::ShowHasMany.new(&config)
end

.has_manysObject



4
5
6
# File 'app/views/resources/show.rb', line 4

def self.has_manys
  @has_manys ||= {}
end

Instance Method Details

#associations_contentObject



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/views/resources/show.rb', line 19

def associations_content
  self.class.has_manys.each do |name, has_many|
    div do
      h2 name
      table do
        thead do
          has_many.columns.each do |column|
            th { text column.name }
          end
        end
        tbody do
          resource.send(name).each do |item|              
            tr class: cycle(:odd, :even) do
              has_many.columns.each do |column|
                td { column.content_for(self, item) }
              end                
            end
          end
        end
      end
    end
  end
end

#body_contentObject



12
13
14
15
16
17
# File 'app/views/resources/show.rb', line 12

def body_content
  p link_to "back to #{resource_name.pluralize} index", collection_path
  p resource.name
  associations_content
  p link_to "edit", edit_resource_path
end