Class: ActiveScaffold::Config::Nested

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

Constant Summary collapse

@@shallow_delete =
true

Constants inherited from Base

Base::NO_FORMATS

Instance Attribute Summary collapse

Attributes inherited from Base

#action_group, #core, #formats, #user_settings_key

Instance Method Summary collapse

Methods inherited from Base

#crud_type, inherited, #label, #model_id, #new_user_settings, #setup_user_setting_key, #user

Methods included from ActiveScaffold::Configurable

#configure, #method_missing, #respond_to_missing?

Constructor Details

#initialize(core_config) ⇒ Nested

Returns a new instance of Nested.



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

def initialize(core_config)
  super
  @label = :add_existing_model
  @shallow_delete = self.class.shallow_delete
  @ignore_order_from_association = self.class.ignore_order_from_association
end

Dynamic Method Handling

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

Instance Attribute Details

#ignore_order_from_associationObject

Returns the value of attribute ignore_order_from_association.



23
24
25
# File 'lib/active_scaffold/config/nested.rb', line 23

def ignore_order_from_association
  @ignore_order_from_association
end

#label=(value) ⇒ Object (writeonly)

the label for this Nested action. used for the header.



50
51
52
# File 'lib/active_scaffold/config/nested.rb', line 50

def label=(value)
  @label = value
end

#shallow_deleteObject

instance-level configuration




21
22
23
# File 'lib/active_scaffold/config/nested.rb', line 21

def shallow_delete
  @shallow_delete
end

Instance Method Details

Add a nested ActionLink

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_scaffold/config/nested.rb', line 26

def add_link(attribute, options = {})
  column = @core.columns[attribute.to_sym]
  raise ArgumentError, "unknown column #{attribute}" if column.nil?
  raise ArgumentError, "column #{attribute} is not an association" if column.association.nil?

  label =
    if column.association.polymorphic?
      column.label
    else
      column.association.klass.model_name.human(:count => column.association.singular? ? 1 : 2, :default => column.association.klass.name.pluralize)
    end
  options.reverse_merge! :security_method => :nested_authorized?, :label => label
  action_group = options.delete(:action_group) || self.action_group
  action_link = @core.link_for_association(column, options)
  @core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
  action_link
end


44
45
46
47
# File 'lib/active_scaffold/config/nested.rb', line 44

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