Class: DisplayFor::Builder::ResourceBase

Inherits:
Base
  • Object
show all
Defined in:
lib/display_for/builder/resource_base.rb

Direct Known Subclasses

View

Instance Attribute Summary collapse

Attributes inherited from Base

#html_options, #namespace, #resource_class, #template

Instance Method Summary collapse

Methods inherited from Base

#action, #attribute, #html

Constructor Details

#initialize(resource, html_options, template, &block) ⇒ ResourceBase

Returns a new instance of ResourceBase.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/display_for/builder/resource_base.rb', line 6

def initialize(resource, html_options, template, &block)
  if resource.is_a?(Array)
    @namespace = resource
    @resource = @namespace.pop
  else
    @namespace = []
    @resource = resource
  end      

  @resource_class = @resource.class

  super(html_options, template, &block)
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/display_for/builder/resource_base.rb', line 4

def resource
  @resource
end

Instance Method Details

#default_actionsObject



20
21
22
23
24
# File 'lib/display_for/builder/resource_base.rb', line 20

def default_actions
  action :list, :link_to => lambda { |r| @namespace + [@resource_class]}, :class => 'btn btn-small'
  action :edit, :link_to => lambda { |r| [:edit] + @namespace + [r] }, :class => 'btn btn-small'
  action :delete, :method => :delete, :confirm => "Are you sure?", :class => 'btn btn-small btn-danger'
end