Skip to content

Commit 06eec3d

Browse files
committed
Moved default table block from Index page to IndexAsTable.
This allows you to pass a set of options to the #index method without passing in a block. The default block will be rendered.
1 parent 2350686 commit 06eec3d

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

features/index/index_scopes.feature

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ Feature: Index Scoping
4949
"""
5050
ActiveAdmin.register Post do
5151
scope :all, :default => true
52-
index :as => :table, :scope_count => false do
53-
column :id
54-
end
52+
index :as => :table, :scope_count => false
5553
end
5654
"""
5755
Then I should see the scope "All" selected

lib/active_admin/views/index_as_table.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,25 @@ def build(page_presenter, collection)
102102
}
103103

104104
table_for collection, table_options do |t|
105-
instance_exec(t, &page_presenter.block)
105+
table_config_block = page_presenter.block || default_table
106+
instance_exec(t, &table_config_block)
106107
end
107108
end
108109

109110
def table_for(*args, &block)
110111
insert_tag IndexTableFor, *args, &block
111112
end
112113

114+
def default_table
115+
proc do
116+
id_column
117+
resource_class.content_columns.each do |col|
118+
column col.name.to_sym
119+
end
120+
default_actions
121+
end
122+
end
123+
113124
#
114125
# Extend the default ActiveAdmin::Views::TableFor with some
115126
# methods for quickly displaying items on the index page

lib/active_admin/views/pages/index.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def main_content
2929
end
3030

3131
protected
32-
33-
32+
3433
# TODO: Refactor to new HTML DSL
3534
def build_download_format_links(formats = [:csv, :xml, :json])
3635
links = formats.collect do |format|
@@ -41,25 +40,20 @@ def build_download_format_links(formats = [:csv, :xml, :json])
4140

4241
def build_scopes
4342
if active_admin_config.scopes.any?
44-
options = {}
45-
options[:scope_count] = config[:scope_count].nil? ? true : config[:scope_count]
46-
43+
scope_options = {
44+
:scope_count => config[:scope_count].nil? ? true : config[:scope_count]
45+
}
46+
4747
div :class => "table_tools" do
48-
scopes_renderer active_admin_config.scopes, options
48+
scopes_renderer active_admin_config.scopes, scope_options
4949
end
5050
end
5151
end
5252

5353
# Creates a default configuration for the resource class. This is a table
5454
# with each column displayed as well as all the default actions
5555
def default_index_config
56-
@default_index_config ||= ::ActiveAdmin::PagePresenter.new(:as => :table) do |display|
57-
id_column
58-
resource_class.content_columns.each do |col|
59-
column col.name.to_sym
60-
end
61-
default_actions
62-
end
56+
@default_index_config ||= ::ActiveAdmin::PagePresenter.new(:as => :table)
6357
end
6458

6559
# Returns the actual class for renderering the main content on the index

0 commit comments

Comments
 (0)