activeadmin 2.13.1 → 2.14.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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +58 -0
  3. data/CONTRIBUTING.md +3 -4
  4. data/README.md +2 -2
  5. data/app/assets/javascripts/active_admin/base.js +1 -4
  6. data/app/assets/stylesheets/active_admin/_forms.scss +1 -1
  7. data/app/assets/stylesheets/active_admin/structure/_footer.scss +6 -1
  8. data/app/views/layouts/active_admin_logged_out.html.erb +5 -4
  9. data/config/locales/fr.yml +3 -3
  10. data/config/locales/vi.yml +34 -7
  11. data/config/locales/zh-CN.yml +36 -17
  12. data/lib/active_admin/asset_registration.rb +3 -3
  13. data/lib/active_admin/authorization_adapter.rb +2 -0
  14. data/lib/active_admin/base_controller/authorization.rb +2 -2
  15. data/lib/active_admin/dependency.rb +0 -4
  16. data/lib/active_admin/engine.rb +1 -1
  17. data/lib/active_admin/filters/resource_extension.rb +4 -4
  18. data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +1 -1
  19. data/lib/active_admin/orm/active_record/comments.rb +8 -8
  20. data/lib/active_admin/pundit_adapter.rb +0 -2
  21. data/lib/active_admin/resource/action_items.rb +2 -2
  22. data/lib/active_admin/version.rb +1 -1
  23. data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -1
  24. data/lib/active_admin/views/index_as_table.rb +1 -1
  25. data/lib/active_admin/views/pages/base.rb +4 -3
  26. data/lib/active_admin/views/pages/index.rb +1 -1
  27. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +17 -0
  28. metadata +5 -44
  29. data/docs/.gitignore +0 -1
  30. data/docs/0-installation.md +0 -142
  31. data/docs/1-general-configuration.md +0 -224
  32. data/docs/10-custom-pages.md +0 -150
  33. data/docs/11-decorators.md +0 -70
  34. data/docs/12-arbre-components.md +0 -214
  35. data/docs/13-authorization-adapter.md +0 -285
  36. data/docs/14-gotchas.md +0 -138
  37. data/docs/2-resource-customization.md +0 -475
  38. data/docs/3-index-pages/custom-index.md +0 -35
  39. data/docs/3-index-pages/index-as-block.md +0 -19
  40. data/docs/3-index-pages/index-as-blog.md +0 -69
  41. data/docs/3-index-pages/index-as-grid.md +0 -27
  42. data/docs/3-index-pages/index-as-table.md +0 -234
  43. data/docs/3-index-pages.md +0 -328
  44. data/docs/4-csv-format.md +0 -74
  45. data/docs/5-forms.md +0 -238
  46. data/docs/6-show-pages.md +0 -93
  47. data/docs/7-sidebars.md +0 -75
  48. data/docs/8-custom-actions.md +0 -177
  49. data/docs/9-batch-actions.md +0 -237
  50. data/docs/CNAME +0 -1
  51. data/docs/Gemfile +0 -4
  52. data/docs/Gemfile.lock +0 -283
  53. data/docs/README.md +0 -24
  54. data/docs/_config.yml +0 -4
  55. data/docs/_includes/footer.html +0 -8
  56. data/docs/_includes/google-analytics.html +0 -16
  57. data/docs/_includes/head.html +0 -7
  58. data/docs/_includes/toc.html +0 -98
  59. data/docs/_includes/top-menu.html +0 -17
  60. data/docs/_layouts/default.html +0 -21
  61. data/docs/documentation.md +0 -60
  62. data/docs/images/activeadmin.png +0 -0
  63. data/docs/images/code-header.png +0 -0
  64. data/docs/images/divider.png +0 -0
  65. data/docs/images/features.png +0 -0
  66. data/docs/images/tidelift.svg +0 -14
  67. data/docs/index.html +0 -226
  68. data/docs/stylesheets/main.css +0 -1205
@@ -1,475 +0,0 @@
1
- ---
2
- redirect_from: /docs/2-resource-customization.html
3
- ---
4
-
5
- # Working with Resources
6
-
7
- Every Active Admin resource corresponds to a Rails model. So before creating a
8
- resource you must first create a Rails model for it.
9
-
10
- ## Create a Resource
11
-
12
- The basic command for creating a resource is `rails g active_admin:resource Post`.
13
- The generator will produce an empty `app/admin/posts.rb` file like so:
14
-
15
- ```ruby
16
- ActiveAdmin.register Post do
17
- # everything happens here :D
18
- end
19
- ```
20
-
21
- ## Setting up Strong Parameters
22
-
23
- Use the `permit_params` method to define which attributes may be changed:
24
-
25
- ```ruby
26
- ActiveAdmin.register Post do
27
- permit_params :title, :content, :publisher_id
28
- end
29
- ```
30
-
31
- Any form field that sends multiple values (such as a HABTM association, or an
32
- array attribute) needs to pass an empty array to `permit_params`:
33
-
34
- If your HABTM is `roles`, you should permit `role_ids: []`
35
-
36
- ```ruby
37
- ActiveAdmin.register Post do
38
- permit_params :title, :content, :publisher_id, role_ids: []
39
- end
40
- ```
41
-
42
- Nested associations in the same form also require an array, but it
43
- needs to be filled with any attributes used.
44
-
45
- ```ruby
46
- ActiveAdmin.register Post do
47
- permit_params :title, :content, :publisher_id,
48
- tags_attributes: [:id, :name, :description, :_destroy]
49
- end
50
-
51
- # Note that `accepts_nested_attributes_for` is still required:
52
- class Post < ActiveRecord::Base
53
- accepts_nested_attributes_for :tags, allow_destroy: true
54
- end
55
- ```
56
-
57
- If you want to dynamically choose which attributes can be set, pass a block:
58
-
59
- ```ruby
60
- ActiveAdmin.register Post do
61
- permit_params do
62
- params = [:title, :content, :publisher_id]
63
- params.push :author_id if current_user.admin?
64
- params
65
- end
66
- end
67
- ```
68
-
69
- If your resource is nested, declare `permit_params` after `belongs_to`:
70
-
71
- ```ruby
72
- ActiveAdmin.register Post do
73
- belongs_to :user
74
- permit_params :title, :content, :publisher_id
75
- end
76
- ```
77
-
78
- The `permit_params` call creates a method called `permitted_params`. You should
79
- use this method when overriding `create` or `update` actions:
80
-
81
- ```ruby
82
- ActiveAdmin.register Post do
83
- controller do
84
- def create
85
- # Good
86
- @post = Post.new(permitted_params[:post])
87
- # Bad
88
- @post = Post.new(params[:post])
89
-
90
- if @post.save
91
- # ...
92
- end
93
- end
94
- end
95
- end
96
- ```
97
-
98
- ## Disabling Actions on a Resource
99
-
100
- All CRUD actions are enabled by default. These can be disabled for a given resource:
101
-
102
- ```ruby
103
- ActiveAdmin.register Post do
104
- actions :all, except: [:update, :destroy]
105
- end
106
- ```
107
-
108
- ## Renaming Action Items
109
-
110
- You can use translations to override labels and page titles for actions such as
111
- new, edit, and destroy by providing a resource specific translation. For
112
- example, to change 'New Offer' to 'Make an Offer' add the following in
113
- config/locales/[en].yml:
114
-
115
- ```yaml
116
- en:
117
- active_admin:
118
- resources:
119
- offer: # Registered resource
120
- new_model: 'Make an Offer' # new action item
121
- edit_model: 'Change Offer' # edit action item
122
- delete_model: 'Cancel Offer' # delete action item
123
- ```
124
-
125
- See the [default en.yml](/config/locales/en.yml) locale file for
126
- existing translations and examples.
127
-
128
- ## Rename the Resource
129
-
130
- By default, any references to the resource (menu, routes, buttons, etc) in the
131
- interface will use the name of the class. You can rename the resource by using
132
- the `:as` option.
133
-
134
- ```ruby
135
- ActiveAdmin.register Post, as: "Article"
136
- ```
137
-
138
- The resource will then be available at `/admin/articles`.
139
-
140
- ## Customize the Namespace
141
-
142
- We use the `admin` namespace by default, but you can use anything:
143
-
144
- ```ruby
145
- # Available at /today/posts
146
- ActiveAdmin.register Post, namespace: :today
147
-
148
- # Available at /posts
149
- ActiveAdmin.register Post, namespace: false
150
- ```
151
-
152
- ## Customize the Menu
153
-
154
- The resource will be displayed in the global navigation by default. To disable
155
- the resource from being displayed in the global navigation:
156
-
157
- ```ruby
158
- ActiveAdmin.register Post do
159
- menu false
160
- end
161
- ```
162
-
163
- The menu method accepts a hash with the following options:
164
-
165
- * `:label` - The string or proc label to display in the menu. If it's a proc, it
166
- will be called each time the menu is rendered.
167
- * `:parent` - The string id (or label) of the parent used for this menu, or an array
168
- of string ids (or labels) for a nested menu
169
- * `:if` - A block or a symbol of a method to call to decide if the menu item
170
- should be displayed
171
- * `:priority` - The integer value of the priority, which defaults to `10`
172
-
173
- ### Labels
174
-
175
- To change the name of the label in the menu:
176
-
177
- ```ruby
178
- ActiveAdmin.register Post do
179
- menu label: "My Posts"
180
- end
181
- ```
182
-
183
- If you want something more dynamic, pass a proc instead:
184
-
185
- ```ruby
186
- ActiveAdmin.register Post do
187
- menu label: proc{ I18n.t "mypost" }
188
- end
189
- ```
190
-
191
- ### Menu Priority
192
-
193
- Menu items are sorted first by their numeric priority, then alphabetically. Since
194
- every menu by default has a priority of `10`, the menu is normally alphabetical.
195
-
196
- You can easily customize this:
197
-
198
- ```ruby
199
- ActiveAdmin.register Post do
200
- menu priority: 1 # so it's on the very left
201
- end
202
- ```
203
-
204
- ### Conditionally Showing / Hiding Menu Items
205
-
206
- Menu items can be shown or hidden at runtime using the `:if` option.
207
-
208
- ```ruby
209
- ActiveAdmin.register Post do
210
- menu if: proc{ current_user.can_edit_posts? }
211
- end
212
- ```
213
-
214
- The proc will be called in the context of the view, so you have access to all
215
- your helpers and current user session information.
216
-
217
- ### Drop Down Menus
218
-
219
- In many cases, a single level navigation will not be enough to manage a large
220
- application. In that case, you can group your menu items under a parent menu item.
221
-
222
- ```ruby
223
- ActiveAdmin.register Post do
224
- menu parent: "Blog"
225
- end
226
- ```
227
-
228
- Note that the "Blog" parent menu item doesn't even have to exist yet; it can be
229
- dynamically generated for you.
230
-
231
- To further nest an item under a submenu, provide an array of parents.
232
-
233
- ```ruby
234
- ActiveAdmin.register Post do
235
- menu parent: ["Admin", "Blog"]
236
- end
237
- ```
238
-
239
- ### Customizing Parent Menu Items
240
-
241
- All of the options given to a standard menu item are also available to
242
- parent menu items. In the case of complex parent menu items, you should
243
- configure them in the Active Admin initializer.
244
-
245
- ```ruby
246
- # config/initializers/active_admin.rb
247
- config.namespace :admin do |admin|
248
- admin.build_menu do |menu|
249
- menu.add label: 'Blog', priority: 0
250
- end
251
- end
252
-
253
- # app/admin/post.rb
254
- ActiveAdmin.register Post do
255
- menu parent: 'Blog'
256
- end
257
- ```
258
-
259
- ### Dynamic Parent Menu Items
260
-
261
- While the above works fine, what if you want a parent menu item with a dynamic
262
- name? Well, you have to refer to it by its `:id`.
263
-
264
- ```ruby
265
- # config/initializers/active_admin.rb
266
- config.namespace :admin do |admin|
267
- admin.build_menu do |menu|
268
- menu.add id: 'blog', label: proc{"Something dynamic"}, priority: 0
269
- end
270
- end
271
-
272
- # app/admin/post.rb
273
- ActiveAdmin.register Post do
274
- menu parent: 'blog'
275
- end
276
- ```
277
-
278
- ### Adding Custom Menu Items
279
-
280
- Sometimes it's not enough to just customize the menu label. In this case, you
281
- can customize the menu for the namespace within the Active Admin initializer.
282
-
283
- ```ruby
284
- # config/initializers/active_admin.rb
285
- config.namespace :admin do |admin|
286
- admin.build_menu do |menu|
287
- menu.add label: "The Application", url: "/", priority: 0
288
-
289
- menu.add label: "Sites" do |sites|
290
- sites.add label: "Google",
291
- url: "http://google.com",
292
- html_options: { target: :blank }
293
-
294
- sites.add label: "Facebook",
295
- url: "http://facebook.com"
296
-
297
- sites.add label: "Github",
298
- url: "http://github.com"
299
- end
300
- end
301
- end
302
- ```
303
-
304
- This will be registered on application start before your resources are loaded.
305
-
306
- ## Scoping the queries
307
-
308
- If your administrators have different access levels, you may sometimes want to
309
- scope what they have access to. Assuming your User model has the proper
310
- has_many relationships, you can simply scope the listings and finders like so:
311
-
312
- ```ruby
313
- ActiveAdmin.register Post do
314
- scope_to :current_user # limits the accessible posts to `current_user.posts`
315
-
316
- # Or if the association doesn't have the default name:
317
- scope_to :current_user, association_method: :blog_posts
318
-
319
- # Finally, you can pass a block to be called:
320
- scope_to do
321
- User.most_popular_posts
322
- end
323
- end
324
- ```
325
-
326
- You can also conditionally apply the scope:
327
-
328
- ```ruby
329
- ActiveAdmin.register Post do
330
- scope_to :current_user, if: proc{ current_user.limited_access? }
331
- scope_to :current_user, unless: proc{ current_user.admin? }
332
- end
333
- ```
334
-
335
- ## Eager loading
336
-
337
- A common way to increase page performance is to eliminate N+1 queries by eager
338
- loading associations:
339
-
340
- ```ruby
341
- ActiveAdmin.register Post do
342
- includes :author, :categories
343
- end
344
- ```
345
-
346
- ## Customizing resource retrieval
347
-
348
- Our controllers are built on [Inherited
349
- Resources](https://github.com/activeadmin/inherited_resources), so you can use
350
- [all of its
351
- features](https://github.com/activeadmin/inherited_resources#overwriting-defaults).
352
-
353
- If you need to customize the collection properties, you can overwrite the
354
- `scoped_collection` method.
355
-
356
- ```ruby
357
- ActiveAdmin.register Post do
358
- controller do
359
- def scoped_collection
360
- end_of_association_chain.where(visibility: true)
361
- end
362
- end
363
- end
364
- ```
365
-
366
- If you need to completely replace the record retrieving code (e.g., you have a
367
- custom `to_param` implementation in your models), override the `find_resource` method
368
- on the controller:
369
-
370
- ```ruby
371
- ActiveAdmin.register Post do
372
- controller do
373
- def find_resource
374
- scoped_collection.where(id: params[:id]).first!
375
- end
376
- end
377
- end
378
- ```
379
-
380
- Note that if you use an authorization library like CanCan, you should be careful
381
- to not write code like this, otherwise **your authorization rules won't be
382
- applied**:
383
-
384
- ```ruby
385
- ActiveAdmin.register Post do
386
- controller do
387
- def find_resource
388
- Post.where(id: params[:id]).first!
389
- end
390
- end
391
- end
392
- ```
393
-
394
- ## Belongs To
395
-
396
- It's common to want to scope a series of resources to a relationship. For
397
- example a Project may have many Milestones and Tickets. To nest the resource
398
- within another, you can use the `belongs_to` method:
399
-
400
- ```ruby
401
- ActiveAdmin.register Project
402
- ActiveAdmin.register Ticket do
403
- belongs_to :project
404
- end
405
- ```
406
-
407
- Projects will be available as usual and tickets will be available by visiting
408
- `/admin/projects/1/tickets` assuming that a Project with the id of 1 exists.
409
- Active Admin does not add "Tickets" to the global navigation because the routes
410
- can only be generated when there is a project id.
411
-
412
- To create links to the resource, you can add them to a sidebar (one of the many
413
- possibilities for how you may with to handle your user interface):
414
-
415
- ```ruby
416
- ActiveAdmin.register Project do
417
-
418
- sidebar "Project Details", only: [:show, :edit] do
419
- ul do
420
- li link_to "Tickets", admin_project_tickets_path(resource)
421
- li link_to "Milestones", admin_project_milestones_path(resource)
422
- end
423
- end
424
- end
425
-
426
- ActiveAdmin.register Ticket do
427
- belongs_to :project
428
- end
429
-
430
- ActiveAdmin.register Milestone do
431
- belongs_to :project
432
- end
433
- ```
434
-
435
- In some cases (like Projects), there are many sub resources and you would
436
- actually like the global navigation to switch when the user navigates "into" a
437
- project. To accomplish this, Active Admin stores the `belongs_to` resources in a
438
- separate menu which you can use if you so wish. To use:
439
-
440
- ```ruby
441
- ActiveAdmin.register Ticket do
442
- belongs_to :project
443
- navigation_menu :project
444
- end
445
-
446
- ActiveAdmin.register Milestone do
447
- belongs_to :project
448
- navigation_menu :project
449
- end
450
- ```
451
-
452
- Now, when you navigate to the tickets section, the global navigation will
453
- only display "Tickets" and "Milestones". When you navigate back to a
454
- non-belongs_to resource, it will switch back to the default menu.
455
-
456
- You can also defer the menu lookup until runtime so that you can dynamically show
457
- different menus, say perhaps based on user permissions. For example:
458
-
459
- ```ruby
460
- ActiveAdmin.register Ticket do
461
- belongs_to :project
462
- navigation_menu do
463
- authorized?(:manage, SomeResource) ? :project : :restricted_menu
464
- end
465
- end
466
- ```
467
-
468
- If you still want your `belongs_to` resources to be available in the default menu
469
- and through non-nested routes, you can use the `:optional` option. For example:
470
-
471
- ```ruby
472
- ActiveAdmin.register Ticket do
473
- belongs_to :project, optional: true
474
- end
475
- ```
@@ -1,35 +0,0 @@
1
- ---
2
- redirect_from: /docs/3-index-pages/custom-index.html
3
- ---
4
-
5
- # Custom Index
6
-
7
- If the supplied Active Admin index components are insufficient for your project
8
- feel free to define your own. Index classes inherit from `ActiveAdmin::Component`
9
- and require a `build` method and an `index_name` class method.
10
-
11
- ```ruby
12
- module ActiveAdmin
13
- module Views
14
- class IndexAsMyIdea < ActiveAdmin::Component
15
-
16
- def build(page_presenter, collection)
17
- # ...
18
- end
19
-
20
- def self.index_name
21
- "my_idea"
22
- end
23
-
24
- end
25
- end
26
- end
27
- ```
28
-
29
- The build method takes a PagePresenter object and collection of whatever you
30
- choose.
31
-
32
- The `index_name` class method takes no arguments and returns a string that should
33
- be representative of the class name. If this method is not defined, your
34
- index component will not be able take advantage of Active Admin's
35
- *multiple index pages* feature.
@@ -1,19 +0,0 @@
1
- ---
2
- redirect_from: /docs/3-index-pages/index-as-block.html
3
- ---
4
-
5
- # Index as a Block
6
-
7
- If you want to fully customize the display of your resources on the index
8
- screen, Index as a Block allows you to render a block of content for each
9
- resource.
10
-
11
- ```ruby
12
- index as: :block do |product|
13
- div for: product do
14
- resource_selection_cell product
15
- h2 auto_link product.title
16
- div simple_format product.description
17
- end
18
- end
19
- ```
@@ -1,69 +0,0 @@
1
- ---
2
- redirect_from: /docs/3-index-pages/index-as-blog.html
3
- ---
4
-
5
- # Index as Blog
6
-
7
- Render your index page as a set of posts. The post has two main options:
8
- title and body.
9
-
10
- ```ruby
11
- index as: :blog do
12
- title :my_title # Calls #my_title on each resource
13
- body :my_body # Calls #my_body on each resource
14
- end
15
- ```
16
-
17
- ## Post Title
18
-
19
- The title is the content that will be rendered within a link to the
20
- resource. There are two main ways to set the content for the title
21
-
22
- First, you can pass in a method to be called on your resource. For example:
23
-
24
- ```ruby
25
- index as: :blog do
26
- title :a_method_to_call
27
- end
28
- ```
29
-
30
- Second, you can pass a block to the tile option which will then be
31
- used as the contents of the title. The resource being rendered
32
- is passed in to the block. For Example:
33
-
34
- ```ruby
35
- index as: :blog do
36
- title do |post|
37
- span post.title, class: 'title'
38
- span post.created_at, class: 'created_at'
39
- end
40
- end
41
- ```
42
-
43
- ## Post Body
44
-
45
- The body is rendered underneath the title of each post. The same two
46
- style of options work as the Post Title above.
47
-
48
- Call a method on the resource as the body:
49
-
50
- ```ruby
51
- index as: :blog do
52
- title :my_title
53
- body :my_body
54
- end
55
- ```
56
-
57
- Or, render a block as the body:
58
-
59
- ```ruby
60
- index as: :blog do
61
- title :my_title
62
- body do |post|
63
- div truncate post.title
64
- div class: 'meta' do
65
- span "Post in #{post.categories.join(', ')}"
66
- end
67
- end
68
- end
69
- ```
@@ -1,27 +0,0 @@
1
- ---
2
- redirect_from: /docs/3-index-pages/index-as-grid.html
3
- ---
4
-
5
- # Index as a Grid
6
-
7
- Sometimes you want to display the index screen for a set of resources as a grid
8
- (possibly a grid of thumbnail images). To do so, use the :grid option for the
9
- index block.
10
-
11
- ```ruby
12
- index as: :grid do |product|
13
- link_to image_tag(product.image_path), admin_product_path(product)
14
- end
15
- ```
16
-
17
- The block is rendered within a cell in the grid once for each resource in the
18
- collection. The resource is passed into the block for you to use in the view.
19
-
20
- You can customize the number of columns that are rendered using the columns
21
- option:
22
-
23
- ```ruby
24
- index as: :grid, columns: 5 do |product|
25
- link_to image_tag(product.image_path), admin_product_path(product)
26
- end
27
- ```