Class: ActiveScaffold::Config::Nested

Inherits:
Base show all
Defined in:
lib/active_scaffold/config/nested.rb

Constant Summary collapse

@@shallow_delete =
true

Instance Attribute Summary collapse

Attributes inherited from Base

#action_group, #user

Instance Method Summary collapse

Methods inherited from Base

#crud_type, #formats, #formats=, inherited

Methods included from ActiveScaffold::Configurable

#configure, #method_missing

Constructor Details

#initialize(core_config) ⇒ Nested

Returns a new instance of Nested.



5
6
7
8
9
# File 'lib/active_scaffold/config/nested.rb', line 5

def initialize(core_config)
  @core = core_config
  self.shallow_delete = self.class.shallow_delete
  @action_group = self.class.action_group.clone if self.class.action_group
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveScaffold::Configurable

Instance Attribute Details

#labelObject



40
41
42
# File 'lib/active_scaffold/config/nested.rb', line 40

def label
  @label ? as_(@label) : as_(:add_existing_model, :model => @core.label)
end

#shallow_deleteObject

instance-level configuration




18
19
20
# File 'lib/active_scaffold/config/nested.rb', line 18

def shallow_delete
  @shallow_delete
end

Instance Method Details

Add a nested ActionLink



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_scaffold/config/nested.rb', line 21

def add_link(attribute, options = {})
  column = @core.columns[attribute.to_sym]
  unless column.nil? || column.association.nil?
    options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) 
    action_link = @core.link_for_association(column, options)
    action_link.action ||= :index
    @core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
  else
    
  end
end


33
34
35
36
# File 'lib/active_scaffold/config/nested.rb', line 33

def add_scoped_link(named_scope, options = {})
  action_link = @core.link_for_association_as_scope(named_scope.to_sym, options)
  @core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
end