Sha256: 993cee57031cfb93a159b02d2bac5720c6a9038931831576d2732ed6118942e7

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

module ActiveScaffold::Config
  class Nested < Base
    self.crud_type = :read

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

    # global level configuration
    # --------------------------
    cattr_accessor :shallow_delete
    @@shallow_delete = true

    # instance-level configuration
    # ----------------------------
    attr_accessor :shallow_delete

    # Add a nested ActionLink
    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)
        @core.action_links.add(action_link) unless action_link.nil?
      else
        
      end
    end
    
    def add_scoped_link(named_scope, options = {})
      action_link = @core.link_for_association_as_scope(named_scope.to_sym, options)
      @core.action_links.add(action_link) unless action_link.nil?
    end

    # the label for this Nested action. used for the header.
    attr_writer :label
    def label
      @label ? as_(@label) : as_(:add_existing_model, :model => @core.label)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_scaffold-3.0.2 lib/active_scaffold/config/nested.rb
active_scaffold-3.0.1 lib/active_scaffold/config/nested.rb
active_scaffold-3.0.0 lib/active_scaffold/config/nested.rb