activeadmin 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeadmin might be problematic. Click here for more details.

Files changed (196) hide show
  1. data/.travis.yml +8 -5
  2. data/CHANGELOG.md +151 -0
  3. data/Gemfile +16 -16
  4. data/LICENSE +1 -1
  5. data/activeadmin.gemspec +1 -0
  6. data/app/assets/images/active_admin/index_list_icons/block_icon.svg +10 -0
  7. data/app/assets/images/active_admin/index_list_icons/blog_icon.svg +4 -0
  8. data/app/assets/images/active_admin/index_list_icons/grid_icon.svg +13 -0
  9. data/app/assets/images/active_admin/index_list_icons/table_icon.svg +3 -0
  10. data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +17 -44
  11. data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +2 -4
  12. data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +0 -3
  13. data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +10 -12
  14. data/app/assets/javascripts/active_admin/pages/application.js.coffee +13 -10
  15. data/app/assets/javascripts/active_admin/pages/batch_actions.js.coffee +3 -3
  16. data/app/assets/stylesheets/active_admin/_base.css.scss +1 -0
  17. data/app/assets/stylesheets/active_admin/_header.css.scss +5 -2
  18. data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +2 -2
  19. data/app/assets/stylesheets/active_admin/components/_index_list.scss +12 -0
  20. data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +2 -2
  21. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +2 -2
  22. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +4 -4
  23. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +5 -4
  24. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +1 -1
  25. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
  26. data/app/assets/stylesheets/active_admin/print.css.scss +2 -2
  27. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +1 -1
  28. data/app/views/active_admin/devise/unlocks/new.html.erb +14 -12
  29. data/docs/1-general-configuration.md +13 -0
  30. data/docs/10-custom-pages.md +40 -28
  31. data/docs/11-decorators.md +6 -4
  32. data/docs/12-arbre-components.md +1 -1
  33. data/docs/13-authorization-adapter.md +206 -0
  34. data/docs/2-resource-customization.md +129 -14
  35. data/docs/3-index-pages.md +65 -0
  36. data/docs/3-index-pages/create-an-index.md +29 -0
  37. data/docs/3-index-pages/index-as-table.md +35 -11
  38. data/docs/5-forms.md +2 -2
  39. data/features/authorization.feature +64 -0
  40. data/features/authorization_cancan.feature +52 -0
  41. data/features/belongs_to.feature +41 -5
  42. data/features/index/batch_actions.feature +27 -3
  43. data/features/index/formats.feature +27 -0
  44. data/features/index/index_as_table.feature +74 -2
  45. data/features/index/index_parameters.feature +69 -0
  46. data/features/index/index_scopes.feature +7 -11
  47. data/features/index/page_title.feature +18 -0
  48. data/features/index/switch_index_view.feature +73 -0
  49. data/features/menu.feature +27 -0
  50. data/features/registering_pages.feature +21 -0
  51. data/features/step_definitions/additional_web_steps.rb +4 -0
  52. data/features/step_definitions/batch_action_steps.rb +16 -6
  53. data/features/step_definitions/index_scope_steps.rb +3 -3
  54. data/features/step_definitions/index_views_steps.rb +3 -0
  55. data/features/step_definitions/menu_steps.rb +4 -0
  56. data/features/support/env.rb +4 -0
  57. data/features/support/paths.rb +3 -0
  58. data/lib/active_admin.rb +4 -0
  59. data/lib/active_admin/application.rb +43 -76
  60. data/lib/active_admin/authorization_adapter.rb +128 -0
  61. data/lib/active_admin/base_controller.rb +18 -1
  62. data/lib/active_admin/base_controller/authorization.rb +153 -0
  63. data/lib/active_admin/base_controller/menu.rb +8 -3
  64. data/lib/active_admin/batch_actions/resource_extension.rb +8 -7
  65. data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
  66. data/lib/active_admin/cancan_adapter.rb +40 -0
  67. data/lib/active_admin/dashboards.rb +4 -5
  68. data/lib/active_admin/dashboards/dashboard_controller.rb +1 -1
  69. data/lib/active_admin/devise.rb +22 -7
  70. data/lib/active_admin/dsl.rb +18 -5
  71. data/lib/active_admin/engine.rb +1 -1
  72. data/lib/active_admin/filters/dsl.rb +1 -1
  73. data/lib/active_admin/filters/forms.rb +9 -7
  74. data/lib/active_admin/filters/resource_extension.rb +20 -15
  75. data/lib/active_admin/form_builder.rb +44 -49
  76. data/lib/active_admin/helpers/optional_display.rb +4 -8
  77. data/lib/active_admin/inputs/filter_boolean_input.rb +1 -1
  78. data/lib/active_admin/inputs/filter_string_input.rb +5 -1
  79. data/lib/active_admin/locales/bg.yml +1 -1
  80. data/lib/active_admin/locales/ca.yml +1 -1
  81. data/lib/active_admin/locales/cs.yml +26 -25
  82. data/lib/active_admin/locales/da.yml +1 -1
  83. data/lib/active_admin/locales/de.yml +1 -1
  84. data/lib/active_admin/locales/en.yml +11 -1
  85. data/lib/active_admin/locales/es.yml +16 -16
  86. data/lib/active_admin/locales/fr.yml +1 -1
  87. data/lib/active_admin/locales/he.yml +1 -1
  88. data/lib/active_admin/locales/hr.yml +1 -1
  89. data/lib/active_admin/locales/hu.yml +1 -1
  90. data/lib/active_admin/locales/it.yml +1 -1
  91. data/lib/active_admin/locales/ja.yml +4 -1
  92. data/lib/active_admin/locales/ko.yml +1 -1
  93. data/lib/active_admin/locales/lt.yml +1 -1
  94. data/lib/active_admin/locales/lv.yml +12 -1
  95. data/lib/active_admin/locales/nl.yml +2 -2
  96. data/lib/active_admin/locales/no-NB.yml +22 -1
  97. data/lib/active_admin/locales/pl.yml +1 -1
  98. data/lib/active_admin/locales/pt-BR.yml +1 -1
  99. data/lib/active_admin/locales/pt-PT.yml +81 -0
  100. data/lib/active_admin/locales/ro.yml +1 -1
  101. data/lib/active_admin/locales/ru.yml +1 -1
  102. data/lib/active_admin/locales/sv-SE.yml +1 -1
  103. data/lib/active_admin/locales/tr.yml +1 -1
  104. data/lib/active_admin/locales/vi.yml +1 -1
  105. data/lib/active_admin/locales/zh-CN.yml +1 -1
  106. data/lib/active_admin/locales/zh-TW.yml +1 -1
  107. data/lib/active_admin/menu.rb +76 -38
  108. data/lib/active_admin/menu_collection.rb +96 -0
  109. data/lib/active_admin/menu_item.rb +61 -71
  110. data/lib/active_admin/namespace.rb +67 -5
  111. data/lib/active_admin/page.rb +6 -0
  112. data/lib/active_admin/page_controller.rb +13 -3
  113. data/lib/active_admin/resource.rb +11 -20
  114. data/lib/active_admin/resource/action_items.rb +3 -3
  115. data/lib/active_admin/resource/controllers.rb +0 -17
  116. data/lib/active_admin/resource/menu.rb +52 -24
  117. data/lib/active_admin/resource/naming.rb +6 -10
  118. data/lib/active_admin/resource/page_presenters.rb +57 -3
  119. data/lib/active_admin/resource/routes.rb +46 -0
  120. data/lib/active_admin/resource_controller.rb +2 -17
  121. data/lib/active_admin/resource_controller/data_access.rb +299 -0
  122. data/lib/active_admin/resource_controller/decorators.rb +2 -1
  123. data/lib/active_admin/resource_dsl.rb +12 -14
  124. data/lib/active_admin/router.rb +61 -56
  125. data/lib/active_admin/scope.rb +28 -18
  126. data/lib/active_admin/version.rb +1 -1
  127. data/lib/active_admin/view_factory.rb +0 -1
  128. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +13 -19
  129. data/lib/active_admin/view_helpers/fields_for.rb +2 -0
  130. data/lib/active_admin/view_helpers/form_helper.rb +1 -1
  131. data/lib/active_admin/view_helpers/method_or_proc_helper.rb +66 -11
  132. data/lib/active_admin/views/components/attributes_table.rb +7 -4
  133. data/lib/active_admin/views/components/index_list.rb +68 -0
  134. data/lib/active_admin/views/components/paginated_collection.rb +13 -9
  135. data/lib/active_admin/views/components/scopes.rb +2 -8
  136. data/lib/active_admin/views/components/table_for.rb +1 -1
  137. data/lib/active_admin/views/footer.rb +1 -1
  138. data/lib/active_admin/views/header.rb +3 -2
  139. data/lib/active_admin/views/index_as_block.rb +4 -0
  140. data/lib/active_admin/views/index_as_blog.rb +4 -0
  141. data/lib/active_admin/views/index_as_grid.rb +4 -0
  142. data/lib/active_admin/views/index_as_table.rb +49 -7
  143. data/lib/active_admin/views/pages/index.rb +19 -4
  144. data/lib/active_admin/views/tabbed_navigation.rb +10 -54
  145. data/lib/generators/active_admin/install/install_generator.rb +5 -1
  146. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +58 -0
  147. data/spec/integration/{default_namespace.rb → default_namespace_spec.rb} +0 -16
  148. data/spec/spec_helper.rb +3 -0
  149. data/spec/support/detect_rails_version.rb +10 -3
  150. data/spec/support/rails_template.rb +1 -1
  151. data/spec/support/templates/post_decorator.rb +6 -6
  152. data/spec/unit/application_spec.rb +5 -5
  153. data/spec/unit/authorization/authorization_adapter_spec.rb +61 -0
  154. data/spec/unit/authorization/controller_authorization_spec.rb +47 -0
  155. data/spec/unit/base_controller_spec.rb +0 -2
  156. data/spec/unit/batch_actions/resource_spec.rb +1 -1
  157. data/spec/unit/breadcrumbs_spec.rb +3 -3
  158. data/spec/unit/cancan_adapter_spec.rb +35 -0
  159. data/spec/unit/config_shared_examples.rb +9 -30
  160. data/spec/unit/devise_spec.rb +29 -0
  161. data/spec/unit/dsl_spec.rb +61 -0
  162. data/spec/unit/filters/filter_form_builder_spec.rb +58 -4
  163. data/spec/unit/filters/resource_spec.rb +17 -5
  164. data/spec/unit/form_builder_spec.rb +15 -0
  165. data/spec/unit/menu_collection_spec.rb +62 -0
  166. data/spec/unit/menu_item_spec.rb +51 -37
  167. data/spec/unit/menu_spec.rb +33 -29
  168. data/spec/unit/namespace/authorization_spec.rb +31 -0
  169. data/spec/unit/namespace/register_page_spec.rb +6 -28
  170. data/spec/unit/namespace/register_resource_spec.rb +11 -34
  171. data/spec/unit/namespace_spec.rb +63 -2
  172. data/spec/unit/page_controller_spec.rb +0 -3
  173. data/spec/unit/reloader_spec.rb +5 -5
  174. data/spec/unit/resource/menu_spec.rb +1 -13
  175. data/spec/unit/resource/naming_spec.rb +20 -2
  176. data/spec/unit/resource/page_presenters_spec.rb +14 -2
  177. data/spec/unit/resource_controller/{collection_spec.rb → data_access_spec.rb} +31 -13
  178. data/spec/unit/resource_controller_spec.rb +4 -5
  179. data/spec/unit/resource_spec.rb +33 -11
  180. data/spec/unit/routing_spec.rb +43 -0
  181. data/spec/unit/scope_spec.rb +13 -0
  182. data/spec/unit/view_factory_spec.rb +0 -1
  183. data/spec/unit/view_helpers/fields_for_spec.rb +4 -0
  184. data/spec/unit/view_helpers/form_helper_spec.rb +6 -2
  185. data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +97 -0
  186. data/spec/unit/views/components/attributes_table_spec.rb +11 -0
  187. data/spec/unit/views/components/index_list_spec.rb +32 -0
  188. data/spec/unit/views/tabbed_navigation_spec.rb +42 -40
  189. data/tasks/test.rake +1 -1
  190. metadata +127 -40
  191. data/lib/active_admin/menu_builder.rb +0 -65
  192. data/lib/active_admin/resource_controller/callbacks.rb +0 -59
  193. data/lib/active_admin/resource_controller/collection.rb +0 -158
  194. data/lib/active_admin/views/utility_nav.rb +0 -41
  195. data/spec/unit/base_controller_shared_examples.rb +0 -25
  196. data/spec/unit/dsl_include_spec.rb +0 -20
@@ -142,4 +142,4 @@ status_tag will generate html markup that Active Admin css uses in styling.
142
142
  :id => 'status_123',
143
143
  :label => 'on'
144
144
  )
145
- # => <span class='status_tag active ok important' id='status_123'>on</span>
145
+ # => <span class='status_tag active ok important' id='status_123'>on</span>
@@ -0,0 +1,206 @@
1
+ # Authorization Adapter
2
+
3
+ Active Admin offers the ability to define and use your own authorization
4
+ adapter. If implemented, the '#authorized?' will be called when an action is
5
+ taken. By default, '#authorized?' returns true.
6
+
7
+
8
+ ## Setting up your own AuthorizationAdapter
9
+
10
+ Setting up your own `AuthorizationAdapter` is easy! The following example shows
11
+ how to set up and tie your authorization adapter class to Active Admin:
12
+
13
+ # app/models/only_authors_authorization.rb
14
+ class OnlyAuthorsAuthorization < ActiveAdmin::AuthorizationAdapter
15
+
16
+ def authorized?(action, subject = nil)
17
+ case subject
18
+ when normalize(Post)
19
+
20
+ # Only let the author update and delete posts
21
+ if action == :update || action == :destroy
22
+ subject.author == user
23
+
24
+ # If it's not an update or destroy, anyone can view it
25
+ else
26
+ true
27
+ end
28
+
29
+ else
30
+ true
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ In order to hook up `OnlyAuthorsAuthorization` to Active Admin, go to your
37
+ application's `config/initializers/active_admin.rb` and add/modify the line:
38
+
39
+ config.authorization_adapter = "OnlyAuthorsAuthorization"
40
+
41
+ Authorization adapters can be configured per ActiveAdmin namespace as well, for example:
42
+
43
+ ActiveAdmin.setup do |config|
44
+ config.namespace :admin do |ns|
45
+ ns.authorization_adapter = "AdminAuthorization"
46
+ end
47
+ config.namespace :my do |ns|
48
+ ns.authorization_adapter = "DashboardAuthorization"
49
+ end
50
+ end
51
+
52
+ Now, whenever a controller action is performed, the `OnlyAuthorsAuthorization`'s
53
+ `#authorized?` method will be called.
54
+
55
+
56
+ ## Getting Access to the Current User
57
+
58
+ From within your authorization adapter, you can call the `#user` method to
59
+ retrieve the current user.
60
+
61
+ class OnlyAdmins < ActiveAdmin::AuthorizationAdapter
62
+
63
+ def authorized?(action, subject = nil)
64
+ user.admin?
65
+ end
66
+
67
+ end
68
+
69
+
70
+ ## Scoping Collections in Authorization Adapters
71
+
72
+ `ActiveAdmin::AuthorizationAdapter` also provides a hook method (`#scope_collection`)
73
+ for the adapter to scope the resource's collection. For example, you may want to
74
+ centralize the scoping:
75
+
76
+ class OnlyMyAccount < ActiveAdmin::AuthorizationAdapter
77
+
78
+ def authorized?(action, subject = nil)
79
+ subject.account == user.account
80
+ end
81
+
82
+ def scope_collection(collection)
83
+ collection.where(:account_id => user.account_id)
84
+ end
85
+
86
+ end
87
+
88
+ All collections presented on Index Screens will be passed through this method
89
+ and will be scoped accordingly.
90
+
91
+
92
+ ## Managing Access to Pages
93
+
94
+ Pages, just like resources, get authorized also. When authorization a page, the
95
+ subject will be an instance of `ActiveAdmin::Page`.
96
+
97
+ class OnlyDashboard < ActiveAdmin::AuthorizationAdapter
98
+ def authorized?(action, subject = nil)
99
+ case subject
100
+ when ActiveAdmin::Page
101
+ if action == :read && subject.name == "Dashboard"
102
+ true
103
+ else
104
+ false
105
+ end
106
+ else
107
+ false
108
+ end
109
+ end
110
+ end
111
+
112
+
113
+ ## Action Types
114
+
115
+ By default Active Admin simplifies the controller actions into 4 actions:
116
+
117
+ * `:read` - This controls if the user can view the menu item as well as the
118
+ index and show screens.
119
+ * `:create` - This controls if the user can view the new screen and submit
120
+ the form to the create action.
121
+ * `:update` - This controls if the user can view the edit screen and submit
122
+ the form to the update action.
123
+ * `:destroy` - This controls if the user can delete a resource.
124
+
125
+ Each of these actions is available as a constant. Eg: `:read` is available as
126
+ `ActiveAdmin::Authorization::READ`.
127
+
128
+
129
+ ## Checking for Authorization in Controllers and Views
130
+
131
+ Active Admin provides a helper method to check if the current user is
132
+ authorized to perform an action on a subject.
133
+
134
+ Simply use the `#authorized?(action, subject) method to check.
135
+
136
+ ActiveAdmin.register Post do
137
+
138
+ index do
139
+ column :title
140
+ column "" do |post|
141
+ if authorized?(:update, post)
142
+ link_to("Edit", admin_post_path(post))
143
+ end
144
+ end
145
+
146
+ end
147
+
148
+ end
149
+
150
+ If you are implementing a custom controller action, you can use the
151
+ `#authorize!` method to raise an `ActiveAdmin::AccessDenied` exception.
152
+
153
+ ActiveAdmin.register Post do
154
+
155
+ member_action :publish, :method => :post do
156
+ post = Post.find(params[:id])
157
+
158
+ authorize! :publish, post
159
+ post.publish!
160
+
161
+ flash[:notice] = "Post has been published"
162
+ redirect_to [:admin, post]
163
+ end
164
+
165
+ action_item :only => :show do
166
+ if !post.published? && authorized?(:publish, post)
167
+ link_to("Publish", publish_admin_post_path(post), :method => :post)
168
+ end
169
+ end
170
+
171
+ end
172
+
173
+
174
+ ## Using the CanCan Adapter
175
+
176
+ Sub-classing `ActiveAdmin::AuthorizationAdapter` is fairly low level. Many times
177
+ it's nicer to have a simpler DSL for managing authorization. Active Admin
178
+ provides an adapter out of the box for [CanCan](https://github.com/ryanb/cancan).
179
+
180
+ To use the CanCan adapter, simply update the configuration in the Active Admin
181
+ initializer:
182
+
183
+ config.authorization_adapter = ActiveAdmin::CanCanAdapter
184
+
185
+ By default this will use the ability class named "Ability". This can also be
186
+ changed from the initializer:
187
+
188
+ config.cancan_ability_class = "MyCustomAbility"
189
+
190
+ Now you can simply use CanCan the way that you would expect and Active Admin
191
+ will use it for authorization:
192
+
193
+ # app/models/ability.rb
194
+ class Ability
195
+ include CanCan::Ability
196
+
197
+ def intialize(user)
198
+ can :manage, Post
199
+ can :read, User
200
+ can :manage, User, :id => user.id
201
+ can :read, ActiveAdmin::Page, :name => "Dashboard"
202
+ end
203
+
204
+ end
205
+
206
+ To view more details about the CanCan API, visit [https://github.com/ryanb/cancan](https://github.com/ryanb/cancan).
@@ -59,6 +59,31 @@ instead of a string. The proc will be called each time the menu is rendered.
59
59
  menu :label => proc{ I18n.t("mypost") }
60
60
  end
61
61
 
62
+ ### Menu Priority
63
+
64
+ By default Active Admin sorts menus alphabetically. Some times you want specific
65
+ resources to show up at the beginning or the end of your menu.
66
+
67
+ Each menu item is given an integer priority value (default 10). You can set it
68
+ to edit the location of the menu item.
69
+
70
+ ActiveAdmin.register Post do
71
+ menu :priority => 1
72
+ end
73
+
74
+ This would ensure that the Post menu item, is at the beginning of the menu.
75
+
76
+ ### Conditionally Showing / Hiding Menu Items
77
+
78
+ Menu items can be shown or hidden at runtime using the `:if` option.
79
+
80
+ ActiveAdmin.register Post do
81
+ menu :if => proc{ current_admin_user.can_edit_posts? }
82
+ end
83
+
84
+ The `proc` will be called in the context of the view, so you have access to all
85
+ your helpers and current user session information.
86
+
62
87
  ### Drop Down Menus
63
88
 
64
89
  In many cases, a single level navigation will not be enough for the
@@ -74,30 +99,49 @@ To add the menu as a child of another menu:
74
99
  Note, the "Blog" menu does not even have to exist yet. It will be generated on
75
100
  the fly as a drop down list for you.
76
101
 
77
- ### Menu Priority
102
+ ### Customizing Parent Menu Items
78
103
 
79
- By default Active Admin sorts menus alphabetically. Some times you want specific
80
- resources to show up at the beginning or the end of your menu.
104
+ All of the options given to a standard menu item are also available to the
105
+ parent menu items. You can customize their attributes in the Active Admin
106
+ initializer.
81
107
 
82
- Each menu item is given an integer priority value (default 10). You can set it
83
- to edit the location of the menu item.
108
+ # config/initializers/active_admin.rb
109
+ ActiveAdmin.setup do |config|
110
+ config.namespace :admin do |admin|
84
111
 
85
- ActiveAdmin.register Post do
86
- menu :priority => 1
112
+ # This block will edit the default menu
113
+ admin.build_menu do |menu|
114
+ menu.add :label => "Blog", :priority => 0
115
+ end
116
+
117
+ end
87
118
  end
88
119
 
89
- This would ensure that the Post menu item, is at the beginning of the menu.
120
+ Now, if you use `menu :parent => "Blog"`, your resource menu item will be a
121
+ child of the Blog menu item with the priority of 0.
90
122
 
91
- ### Conditionally Showing / Hiding Menu Items
123
+ ### Adding Custom Menu Items
92
124
 
93
- Menu items can be shown or hidden at runtime using the `:if` option.
125
+ Sometimes it's not enough to just customize the menu label. In this case, you
126
+ can customize the menu for the namespace within the Active Admin initializer.
94
127
 
95
- ActiveAdmin.register Post do
96
- menu :if => proc{ current_admin_user.can_edit_posts? }
128
+ # config/initializers/active_admin.rb
129
+ ActiveAdmin.setup do |config|
130
+ config.namespace :admin do |admin|
131
+ admin.build_menu do |menu|
132
+ menu.add :label => "The Application", :url => "/", :priority => 0
133
+
134
+ menu.add :label => "Sites" do |sites|
135
+ sites.add :label => "Google", :url => "http://google.com", :html_options => { :target => :blank }
136
+ sites.add :label => "Facebook", :url => "http://facebook.com"
137
+ sites.add :label => "Github", :url => "http://github.com"
138
+ end
139
+ end
140
+ end
97
141
  end
98
142
 
99
- The `proc` will be called in the context of the view, so you have access to all
100
- your helpers and current user session information.
143
+ This block will be run once on application startup to build the menu before each
144
+ of the resources are added to it.
101
145
 
102
146
  ## Scoping the queries
103
147
 
@@ -160,3 +204,74 @@ If you need to completely replace the record retrieving code (e.g., you have a c
160
204
  In fact, the controllers use [Inherited Resource](https://github.com/josevalim/inherited_resources),
161
205
  so you can use all the
162
206
  [customization features in Inherited Resource](https://github.com/josevalim/inherited_resources#overwriting-defaults).
207
+
208
+
209
+ ## Belongs To
210
+
211
+ It's common to want to scope a series of resources to a relationship. For
212
+ example a Project may have many Milestones and Tickets. To nest the resource
213
+ within another, you can use the `belongs_to` method:
214
+
215
+ ActiveAdmin.register Project do
216
+ end
217
+
218
+ ActiveAdmin.register Ticket do
219
+ belongs_to :project
220
+ end
221
+
222
+ Projects will be available as usual and tickets will be availble by visiting
223
+ "/admin/projects/1/tickets" assuming that a Project with the id of 1 exists.
224
+ Active Admin does not add "Tickets" to the global navigation because the routes
225
+ can only be generated when there is a project id.
226
+
227
+ To create links to the resource, you can add them to a sidebar (one of the many
228
+ possibilities for how you may with to handle your user interface):
229
+
230
+ ActiveAdmin.register Project do
231
+
232
+ sidebar "Project Details" do
233
+ ul do
234
+ li link_to("Tickets", admin_project_tickets_path(project))
235
+ li link_to("Milestones", admin_project_milestones_path(project))
236
+ end
237
+ end
238
+
239
+ end
240
+
241
+ ActiveAdmin.register Ticket do
242
+ belongs_to :project
243
+ end
244
+
245
+ ActiveAdmin.register Milestone do
246
+ belongs_to :project
247
+ end
248
+
249
+
250
+ In some cases (like Projects), there are many sub resources and you would
251
+ actually like the global navigation to switch when the user navigates "into" a
252
+ project. To accomplish this, Active Admin stores the `belongs_to` resources in a
253
+ seperate menu which you can use if you so wish. To use:
254
+
255
+ ActiveAdmin.register Ticket do
256
+ belongs_to :project
257
+ navigation_menu :project
258
+ end
259
+
260
+ ActiveAdmin.register Milestone do
261
+ belongs_to :project
262
+ navigation_menu :project
263
+ end
264
+
265
+ Now, when you navigate to the tickets section, the global navigation will
266
+ only display "Tickets" and "Milestones". When you navigate back to a
267
+ non-belongs_to resource, it will switch back to the default menu.
268
+
269
+ You can also defer the menu lookup until runtime so that you can dynamically show
270
+ different menus, say perhaps on user permissions or level. For example:
271
+
272
+ ActiveAdmin.register Ticket do
273
+ belongs_to: :project
274
+ navigation_menu do
275
+ authorized?(:manage, SomeResource) ? :project : :restricted_menu
276
+ end
277
+ end
@@ -14,6 +14,44 @@ Built in, Active Admin has the following index renderers:
14
14
  All index pages also support scopes, filters, pagination, action items, and
15
15
  sidebar sections.
16
16
 
17
+ ## Multiple Index Pages
18
+
19
+ Sometime you may want more than one index page for a resource to represent
20
+ different views to the user. If multiple index pages exist, Active Admin will
21
+ automatically build links at the top of the default index page. Including
22
+ multiple views is simple and requires creating multiple index components in
23
+ your resource.
24
+
25
+ index do
26
+ column :image_title
27
+ default_actions
28
+ end
29
+
30
+ index :as => :grid do |product|
31
+ link_to(image_tag(product.image_path), admin_product_path(product))
32
+ end
33
+
34
+ The first index component will be the default index page unless you indicate
35
+ otherwise by setting :default to true.
36
+
37
+ index do
38
+ column :image_title
39
+ default_actions
40
+ end
41
+
42
+ index :as => :grid, :default => true do |product|
43
+ link_to(image_tag(product.image_path), admin_product_path(product))
44
+ end
45
+
46
+ Active Admin does not limit the index page to be a table, block, blog or grid.
47
+ If you've [created your own index page](3-index-pages/create-an-index.md) it can be included by setting :as to the
48
+ class of the index component you created.
49
+
50
+ index :as => ActiveAdmin::Views::IndexAsTable do
51
+ column :image_title
52
+ default_actions
53
+ end
54
+
17
55
  ## Index Filters
18
56
 
19
57
  By default the index screen includes a "Filters" sidebar on the right hand side
@@ -112,3 +150,30 @@ You can remove links to download CSV, XML and JSON exports:
112
150
  index :download_links => false do
113
151
  end
114
152
 
153
+ ## Customizing Download Links
154
+
155
+ There are multiple ways to either remove the download links per resource listing, or customize the formats that are shown. Customize the formats by passing an array of symbols, or pass false to hide entirely.
156
+
157
+ Customizing the download links per resource:
158
+
159
+ ActiveAdmin.register Post do
160
+
161
+ # hide the links entirely
162
+ index :download_links => false
163
+
164
+ # only show a PDF export
165
+ index :download_links => [:pdf]
166
+
167
+ end
168
+
169
+ If you want to customize download links for every resource throughout the application, configure that in the `active_admin` initializer.
170
+
171
+ ActiveAdmin.setup do |config|
172
+
173
+ # Disable entirely
174
+ config.download_links = false
175
+
176
+ # Want PDF added to default download links
177
+ config.download_links = [:csv, :xml, :json, :pdf]
178
+
179
+ end