Module: ActiveScaffold::Actions::DeletedRecords

Defined in:
lib/active_scaffold/bridges/paper_trail/actions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


3
4
5
6
7
8
9
10
# File 'lib/active_scaffold/bridges/paper_trail/actions.rb', line 3

def self.included(base)
  base.class_eval do
    config = active_scaffold_config
    if config.actions.include?(:nested) && config.deleted_records.nested_link_group
      config.configure { nested.add_link :versions, :label => config.deleted_records.nested_link_label, :action_group => config.deleted_records.nested_link_group }
    end
  end
end

Instance Method Details

#deletedObject


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_scaffold/bridges/paper_trail/actions.rb', line 12

def deleted
  query = PaperTrail::Version.destroys.where(:item_type => active_scaffold_config.model)
  if nested? && nested.child_association&.belongs_to? && PaperTrail::Version.respond_to?(:where_object)
    query = query.where_object(nested.child_association.foreign_key => nested.parent_id)
  end
  pager = Paginator.new(query.count, active_scaffold_config.list.per_page) do |offset, per_page|
    query.offset(offset).limit(per_page).map(&:reify)
  end
  @pagination_action = :deleted
  @page = pager.page(params[:page] || 1)
  @records = @page.items
  respond_to_action(:list)
end