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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +58 -0
- data/CONTRIBUTING.md +3 -4
- data/README.md +2 -2
- data/app/assets/javascripts/active_admin/base.js +1 -4
- data/app/assets/stylesheets/active_admin/_forms.scss +1 -1
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +6 -1
- data/app/views/layouts/active_admin_logged_out.html.erb +5 -4
- data/config/locales/fr.yml +3 -3
- data/config/locales/vi.yml +34 -7
- data/config/locales/zh-CN.yml +36 -17
- data/lib/active_admin/asset_registration.rb +3 -3
- data/lib/active_admin/authorization_adapter.rb +2 -0
- data/lib/active_admin/base_controller/authorization.rb +2 -2
- data/lib/active_admin/dependency.rb +0 -4
- data/lib/active_admin/engine.rb +1 -1
- data/lib/active_admin/filters/resource_extension.rb +4 -4
- data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +1 -1
- data/lib/active_admin/orm/active_record/comments.rb +8 -8
- data/lib/active_admin/pundit_adapter.rb +0 -2
- data/lib/active_admin/resource/action_items.rb +2 -2
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -1
- data/lib/active_admin/views/index_as_table.rb +1 -1
- data/lib/active_admin/views/pages/base.rb +4 -3
- data/lib/active_admin/views/pages/index.rb +1 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +17 -0
- metadata +5 -44
- data/docs/.gitignore +0 -1
- data/docs/0-installation.md +0 -142
- data/docs/1-general-configuration.md +0 -224
- data/docs/10-custom-pages.md +0 -150
- data/docs/11-decorators.md +0 -70
- data/docs/12-arbre-components.md +0 -214
- data/docs/13-authorization-adapter.md +0 -285
- data/docs/14-gotchas.md +0 -138
- data/docs/2-resource-customization.md +0 -475
- data/docs/3-index-pages/custom-index.md +0 -35
- data/docs/3-index-pages/index-as-block.md +0 -19
- data/docs/3-index-pages/index-as-blog.md +0 -69
- data/docs/3-index-pages/index-as-grid.md +0 -27
- data/docs/3-index-pages/index-as-table.md +0 -234
- data/docs/3-index-pages.md +0 -328
- data/docs/4-csv-format.md +0 -74
- data/docs/5-forms.md +0 -238
- data/docs/6-show-pages.md +0 -93
- data/docs/7-sidebars.md +0 -75
- data/docs/8-custom-actions.md +0 -177
- data/docs/9-batch-actions.md +0 -237
- data/docs/CNAME +0 -1
- data/docs/Gemfile +0 -4
- data/docs/Gemfile.lock +0 -283
- data/docs/README.md +0 -24
- data/docs/_config.yml +0 -4
- data/docs/_includes/footer.html +0 -8
- data/docs/_includes/google-analytics.html +0 -16
- data/docs/_includes/head.html +0 -7
- data/docs/_includes/toc.html +0 -98
- data/docs/_includes/top-menu.html +0 -17
- data/docs/_layouts/default.html +0 -21
- data/docs/documentation.md +0 -60
- data/docs/images/activeadmin.png +0 -0
- data/docs/images/code-header.png +0 -0
- data/docs/images/divider.png +0 -0
- data/docs/images/features.png +0 -0
- data/docs/images/tidelift.svg +0 -14
- data/docs/index.html +0 -226
- data/docs/stylesheets/main.css +0 -1205
data/docs/5-forms.md
DELETED
@@ -1,238 +0,0 @@
|
|
1
|
-
---
|
2
|
-
redirect_from: /docs/5-forms.html
|
3
|
-
---
|
4
|
-
|
5
|
-
# Forms
|
6
|
-
|
7
|
-
Active Admin gives you complete control over the output of the form by creating
|
8
|
-
a thin DSL on top of [Formtastic](https://github.com/justinfrench/formtastic):
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
ActiveAdmin.register Post do
|
12
|
-
|
13
|
-
form title: 'A custom title' do |f|
|
14
|
-
inputs 'Details' do
|
15
|
-
input :title
|
16
|
-
input :published_at, label: "Publish Post At"
|
17
|
-
li "Created at #{f.object.created_at}" unless f.object.new_record?
|
18
|
-
input :category
|
19
|
-
end
|
20
|
-
panel 'Markup' do
|
21
|
-
"The following can be used in the content below..."
|
22
|
-
end
|
23
|
-
inputs 'Content', :body
|
24
|
-
para "Press cancel to return to the list without saving."
|
25
|
-
actions
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
```
|
30
|
-
|
31
|
-
For more details, please see [Formtastic's documentation](https://github.com/justinfrench/formtastic/wiki).
|
32
|
-
|
33
|
-
## Default
|
34
|
-
|
35
|
-
Resources come with a default form defined as such:
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
form do |f|
|
39
|
-
f.semantic_errors # shows errors on :base
|
40
|
-
f.inputs # builds an input field for every attribute
|
41
|
-
f.actions # adds the 'Submit' and 'Cancel' buttons
|
42
|
-
end
|
43
|
-
```
|
44
|
-
|
45
|
-
## Partials
|
46
|
-
|
47
|
-
If you want to split a custom form into a separate partial use:
|
48
|
-
|
49
|
-
```ruby
|
50
|
-
ActiveAdmin.register Post do
|
51
|
-
form partial: 'form'
|
52
|
-
end
|
53
|
-
```
|
54
|
-
|
55
|
-
Which looks for something like this:
|
56
|
-
|
57
|
-
```ruby
|
58
|
-
# app/views/admin/posts/_form.html.arb
|
59
|
-
active_admin_form_for [:admin, resource] do |f|
|
60
|
-
inputs :title, :body
|
61
|
-
actions
|
62
|
-
end
|
63
|
-
```
|
64
|
-
|
65
|
-
This is a regular Rails partial so any template engine may be used.
|
66
|
-
|
67
|
-
You can also use the `ActiveAdmin::FormBuilder` as builder in your Formtastic
|
68
|
-
Form for use the same helpers are used in the admin file:
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
= semantic_form_for [:admin, @post], builder: ActiveAdmin::FormBuilder do |f|
|
72
|
-
= f.inputs "Details" do
|
73
|
-
= f.input :title
|
74
|
-
- f.has_many :taggings, sortable: :position, sortable_start: 1 do |t|
|
75
|
-
- t.input :tag
|
76
|
-
= f.actions
|
77
|
-
|
78
|
-
```
|
79
|
-
|
80
|
-
## Nested Resources
|
81
|
-
|
82
|
-
You can create forms with nested models using the `has_many` method, even if
|
83
|
-
your model uses `has_one`:
|
84
|
-
|
85
|
-
```ruby
|
86
|
-
ActiveAdmin.register Post do
|
87
|
-
permit_params :title,
|
88
|
-
:published_at,
|
89
|
-
:body,
|
90
|
-
categories_attributes: [:id, :title, :_destroy],
|
91
|
-
taggings_attributes: [:id, :tag],
|
92
|
-
comment_attributes: [:id, :body, :_destroy]
|
93
|
-
|
94
|
-
form do |f|
|
95
|
-
f.inputs 'Details' do
|
96
|
-
f.input :title
|
97
|
-
f.input :published_at, label: 'Publish Post At'
|
98
|
-
end
|
99
|
-
f.inputs 'Content', :body
|
100
|
-
f.inputs do
|
101
|
-
f.has_many :categories, heading: 'Themes',
|
102
|
-
allow_destroy: true,
|
103
|
-
new_record: false do |a|
|
104
|
-
a.input :title
|
105
|
-
end
|
106
|
-
end
|
107
|
-
f.inputs do
|
108
|
-
f.has_many :taggings, sortable: :position, sortable_start: 1 do |t|
|
109
|
-
t.input :tag
|
110
|
-
end
|
111
|
-
end
|
112
|
-
f.inputs do
|
113
|
-
f.has_many :comments,
|
114
|
-
new_record: 'Leave Comment',
|
115
|
-
remove_record: 'Remove Comment',
|
116
|
-
allow_destroy: -> (c) { c.author?(current_admin_user) } do |b|
|
117
|
-
b.input :body
|
118
|
-
end
|
119
|
-
end
|
120
|
-
f.actions
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
```
|
125
|
-
|
126
|
-
*NOTE*: In addition to using `has_many` as illustrated above, you'll need to add
|
127
|
-
`accepts_nested_attributes` to your parent model and [configure strong parameters](https://activeadmin.info/2-resource-customization.html)
|
128
|
-
|
129
|
-
The `:allow_destroy` option adds a checkbox to the end of the nested form allowing
|
130
|
-
removal of the child object upon submission. Be sure to set `allow_destroy: true`
|
131
|
-
on the association to use this option. It is possible to associate
|
132
|
-
`:allow_destroy` with a string or a symbol, corresponding to the name of a child
|
133
|
-
object's method that will get called, or with a Proc object. The Proc object
|
134
|
-
receives the child object as a parameter and should return either true or false.
|
135
|
-
|
136
|
-
The `:heading` option adds a custom heading. You can hide it entirely by passing
|
137
|
-
`false`.
|
138
|
-
|
139
|
-
The `:new_record` option controls the visibility of the new record button (shown
|
140
|
-
by default). If you pass a string, it will be used as the text for the new
|
141
|
-
record button.
|
142
|
-
|
143
|
-
The `:remove_record` option controls the text of the remove button (shown after
|
144
|
-
the new record button is pressed). If you pass a string, it will be used as the
|
145
|
-
text for the remove button.
|
146
|
-
|
147
|
-
The `:sortable` option adds a hidden field and will enable drag & drop sorting
|
148
|
-
of the children. It expects the name of the column that will store the index of
|
149
|
-
each child.
|
150
|
-
|
151
|
-
The `:sortable_start` option sets the value (0 by default) of the first position
|
152
|
-
in the list.
|
153
|
-
|
154
|
-
## Datepicker
|
155
|
-
|
156
|
-
ActiveAdmin offers the `datepicker` input, which uses the [jQuery UI
|
157
|
-
datepicker](http://jqueryui.com/datepicker/). The datepicker input accepts any
|
158
|
-
of the options available to the standard jQueryUI Datepicker. For example:
|
159
|
-
|
160
|
-
```ruby
|
161
|
-
form do |f|
|
162
|
-
f.input :starts_at, as: :datepicker,
|
163
|
-
datepicker_options: {
|
164
|
-
min_date: "2013-10-8",
|
165
|
-
max_date: "+3D"
|
166
|
-
}
|
167
|
-
|
168
|
-
f.input :ends_at, as: :datepicker,
|
169
|
-
datepicker_options: {
|
170
|
-
min_date: 3.days.ago.to_date,
|
171
|
-
max_date: "+1W +5D"
|
172
|
-
}
|
173
|
-
end
|
174
|
-
```
|
175
|
-
|
176
|
-
Datepicker also accepts the `:label` option as a string or proc to display.
|
177
|
-
If it's a proc, it will be called each time the datepicker is rendered.
|
178
|
-
|
179
|
-
## Displaying Errors
|
180
|
-
|
181
|
-
To display a list of all validation errors:
|
182
|
-
|
183
|
-
```ruby
|
184
|
-
form do |f|
|
185
|
-
f.semantic_errors *f.object.errors.attribute_names
|
186
|
-
|
187
|
-
# ...
|
188
|
-
end
|
189
|
-
```
|
190
|
-
|
191
|
-
This is particularly useful to display errors on virtual or hidden attributes.
|
192
|
-
|
193
|
-
# Tabs
|
194
|
-
|
195
|
-
You can arrange content in tabs as shown below:
|
196
|
-
|
197
|
-
```ruby
|
198
|
-
form do |f|
|
199
|
-
tabs do
|
200
|
-
tab 'Basic' do
|
201
|
-
f.inputs 'Basic Details' do
|
202
|
-
f.input :email
|
203
|
-
f.input :password
|
204
|
-
f.input :password_confirmation
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
tab 'Advanced', html_options: { class: 'specific_css_class' } do
|
209
|
-
f.inputs 'Advanced Details' do
|
210
|
-
f.input :role
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
f.actions
|
215
|
-
end
|
216
|
-
```
|
217
|
-
|
218
|
-
`html_options` allows you set additional html params for tab's menu item.
|
219
|
-
|
220
|
-
# Customize the Create Another checkbox
|
221
|
-
|
222
|
-
In order to simplify creating multiple resources you may enable ActiveAdmin to
|
223
|
-
show nice "Create Another" checkbox alongside of Create Model button. It may be
|
224
|
-
enabled for the whole application:
|
225
|
-
|
226
|
-
```ruby
|
227
|
-
ActiveAdmin.setup do |config|
|
228
|
-
config.create_another = true
|
229
|
-
end
|
230
|
-
```
|
231
|
-
|
232
|
-
or for the particular resource:
|
233
|
-
|
234
|
-
```ruby
|
235
|
-
ActiveAdmin.register Post do
|
236
|
-
config.create_another = true
|
237
|
-
end
|
238
|
-
```
|
data/docs/6-show-pages.md
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
---
|
2
|
-
redirect_from: /docs/6-show-pages.html
|
3
|
-
---
|
4
|
-
# Customize the Show Page
|
5
|
-
|
6
|
-
The show block is rendered within the context of the view and uses
|
7
|
-
[Arbre](https://github.com/activeadmin/arbre) syntax.
|
8
|
-
|
9
|
-
With the `show` block, you can render anything you want.
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
ActiveAdmin.register Post do
|
13
|
-
show do
|
14
|
-
h3 post.title
|
15
|
-
div do
|
16
|
-
simple_format post.body
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
```
|
21
|
-
|
22
|
-
You can render a partial at any point:
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
ActiveAdmin.register Post do
|
26
|
-
show do
|
27
|
-
# renders app/views/admin/posts/_some_partial.html.erb
|
28
|
-
render 'some_partial', { post: post }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
```
|
32
|
-
|
33
|
-
If you'd like to keep the default AA look, you can use `attributes_table`:
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
ActiveAdmin.register Ad do
|
37
|
-
show do
|
38
|
-
attributes_table do
|
39
|
-
row :title
|
40
|
-
row :image do |ad|
|
41
|
-
image_tag ad.image.url
|
42
|
-
end
|
43
|
-
end
|
44
|
-
active_admin_comments
|
45
|
-
end
|
46
|
-
end
|
47
|
-
```
|
48
|
-
|
49
|
-
You can also customize the title of the object in the show screen:
|
50
|
-
|
51
|
-
```ruby
|
52
|
-
show title: :name do
|
53
|
-
# ...
|
54
|
-
end
|
55
|
-
```
|
56
|
-
|
57
|
-
If you want a more data-dense page, you can combine a sidebar:
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
ActiveAdmin.register Book do
|
61
|
-
show do
|
62
|
-
panel "Table of Contents" do
|
63
|
-
table_for book.chapters do
|
64
|
-
column :number
|
65
|
-
column :title
|
66
|
-
column :page
|
67
|
-
end
|
68
|
-
end
|
69
|
-
active_admin_comments
|
70
|
-
end
|
71
|
-
|
72
|
-
sidebar "Details", only: :show do
|
73
|
-
attributes_table_for book do
|
74
|
-
row :title
|
75
|
-
row :author
|
76
|
-
row :publisher
|
77
|
-
row('Published?') { |b| status_tag b.published? }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
```
|
82
|
-
|
83
|
-
If you want to keep the default show data, but add something extra to it:
|
84
|
-
|
85
|
-
```ruby
|
86
|
-
show do
|
87
|
-
div do
|
88
|
-
h3 'Some custom charts about this object'
|
89
|
-
render partial: 'charts'
|
90
|
-
end
|
91
|
-
default_main_content
|
92
|
-
end
|
93
|
-
```
|
data/docs/7-sidebars.md
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
---
|
2
|
-
redirect_from: /docs/7-sidebars.html
|
3
|
-
---
|
4
|
-
# Sidebar Sections
|
5
|
-
|
6
|
-
Sidebars allow you to put whatever content you want on the side the page.
|
7
|
-
|
8
|
-
```ruby
|
9
|
-
sidebar :help do
|
10
|
-
"Need help? Email us at help@example.com"
|
11
|
-
end
|
12
|
-
```
|
13
|
-
|
14
|
-
This will generate a sidebar on every page for that resource. The first
|
15
|
-
argument is used as the title, and can be a symbol, string, or lambda.
|
16
|
-
|
17
|
-
You can also use [Arbre](https://github.com/activeadmin/arbre) to define HTML content.
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
sidebar :help do
|
21
|
-
ul do
|
22
|
-
li "Second List First Item"
|
23
|
-
li "Second List Second Item"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
```
|
27
|
-
|
28
|
-
Sidebars can be rendered on a specific action by passing `:only` or `:except`.
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
sidebar :help, only: :index do
|
32
|
-
"Need help? Email us at help@example.com"
|
33
|
-
end
|
34
|
-
```
|
35
|
-
|
36
|
-
If you want to conditionally display a sidebar section, use the :if option and
|
37
|
-
pass it a proc which will be rendered within the view context.
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
sidebar :help, if: proc{ current_admin_user.super_admin? } do
|
41
|
-
"Only for super admins!"
|
42
|
-
end
|
43
|
-
```
|
44
|
-
|
45
|
-
You can access your model as resource in the sidebar too:
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
sidebar :custom, only: :show do
|
49
|
-
resource.a_method
|
50
|
-
end
|
51
|
-
```
|
52
|
-
|
53
|
-
You can also render a partial:
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
sidebar :help # app/views/admin/posts/_help_sidebar.html.erb
|
57
|
-
sidebar :help, partial: 'custom' # app/views/admin/posts/_custom.html.erb
|
58
|
-
```
|
59
|
-
|
60
|
-
It's possible to add custom class name to the sidebar parent element by passing
|
61
|
-
`class` option:
|
62
|
-
|
63
|
-
```ruby
|
64
|
-
sidebar :help, class: 'custom_class'
|
65
|
-
```
|
66
|
-
|
67
|
-
By default sidebars are positioned in the same order as they defined, but it's also
|
68
|
-
possible to specify their position manually:
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
# will push Help section to the top (above default Filters section)
|
72
|
-
sidebar :help, priority: 0
|
73
|
-
```
|
74
|
-
|
75
|
-
Default sidebar priority is `10`.
|
data/docs/8-custom-actions.md
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
---
|
2
|
-
redirect_from: /docs/8-custom-actions.html
|
3
|
-
---
|
4
|
-
|
5
|
-
# Custom Controller Actions
|
6
|
-
|
7
|
-
Active Admin allows you to override and modify the underlying controller which
|
8
|
-
is generated for you. There are helpers to add collection and member actions, or
|
9
|
-
you can drop right in to the controller and modify its behavior.
|
10
|
-
|
11
|
-
## Collection Actions
|
12
|
-
|
13
|
-
A collection action is a controller action which operates on the collection of
|
14
|
-
resources. This method adds both the action to the controller as well as
|
15
|
-
generating a route for you.
|
16
|
-
|
17
|
-
To add a collection action, use the collection_action method:
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
ActiveAdmin.register Post do
|
21
|
-
|
22
|
-
collection_action :import_csv, method: :post do
|
23
|
-
# Do some CSV importing work here...
|
24
|
-
redirect_to collection_path, notice: "CSV imported successfully!"
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
```
|
29
|
-
|
30
|
-
This collection action will generate a route at `/admin/posts/import_csv`
|
31
|
-
pointing to the `Admin::PostsController#import_csv` controller action.
|
32
|
-
|
33
|
-
## Member Actions
|
34
|
-
|
35
|
-
A member action is a controller action which operates on a single resource.
|
36
|
-
|
37
|
-
For example, to add a lock action to a user resource, you would do the
|
38
|
-
following:
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
ActiveAdmin.register User do
|
42
|
-
|
43
|
-
member_action :lock, method: :put do
|
44
|
-
resource.lock!
|
45
|
-
redirect_to resource_path, notice: "Locked!"
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
```
|
50
|
-
|
51
|
-
This will generate a route at `/admin/users/:id/lock` pointing to the
|
52
|
-
`Admin::UserController#lock` controller action.
|
53
|
-
|
54
|
-
## HTTP Verbs
|
55
|
-
|
56
|
-
The `collection_action` and `member_action` methods both accept the `:method`
|
57
|
-
argument to set the HTTP verb for the controller action and route.
|
58
|
-
|
59
|
-
Sometimes you want to create an action with the same name, that handles multiple
|
60
|
-
HTTP verbs. In that case, this is the suggested approach:
|
61
|
-
|
62
|
-
```ruby
|
63
|
-
member_action :foo, method: [:get, :post] do
|
64
|
-
if request.post?
|
65
|
-
resource.update! foo: params[:foo] || {}
|
66
|
-
head :ok
|
67
|
-
else
|
68
|
-
render :foo
|
69
|
-
end
|
70
|
-
end
|
71
|
-
```
|
72
|
-
|
73
|
-
## Rendering
|
74
|
-
|
75
|
-
Custom controller actions support rendering within the standard Active Admin
|
76
|
-
layout.
|
77
|
-
|
78
|
-
```ruby
|
79
|
-
ActiveAdmin.register Post do
|
80
|
-
|
81
|
-
# /admin/posts/:id/comments
|
82
|
-
member_action :comments do
|
83
|
-
@comments = resource.comments
|
84
|
-
# This will render app/views/admin/posts/comments.html.erb
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
```
|
89
|
-
|
90
|
-
If you would like to use the same view syntax as the rest of Active Admin, you
|
91
|
-
can use the Arbre file extension: .arb.
|
92
|
-
|
93
|
-
For example, create `app/views/admin/posts/comments.html.arb` with:
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
table_for assigns[:post].comments do
|
97
|
-
column :id
|
98
|
-
column :author
|
99
|
-
column :body do |comment|
|
100
|
-
simple_format comment.body
|
101
|
-
end
|
102
|
-
end
|
103
|
-
```
|
104
|
-
|
105
|
-
## Page Titles
|
106
|
-
|
107
|
-
The page title for the custom action will be the translated version of
|
108
|
-
the controller action name. For example, a member_action named "upload_csv" will
|
109
|
-
look up a translation key of `active_admin.upload_csv`. If none are found, it
|
110
|
-
defaults to the name of the controller action.
|
111
|
-
|
112
|
-
If this doesn't work for you, you can always set the `@page_title` instance
|
113
|
-
variable in your controller action to customize the page title.
|
114
|
-
|
115
|
-
```ruby
|
116
|
-
ActiveAdmin.register Post do
|
117
|
-
|
118
|
-
member_action :comments do
|
119
|
-
@comments = resource.comments
|
120
|
-
@page_title = "#{resource.title}: Comments" # Sets the page title
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
```
|
125
|
-
|
126
|
-
# Action Items
|
127
|
-
|
128
|
-
To include your own action items (like the New, Edit and Delete buttons), add an
|
129
|
-
`action_item` block. The first parameter is just a name to identify the action,
|
130
|
-
and is required. For example, to add a "View on site" button to view a blog
|
131
|
-
post:
|
132
|
-
|
133
|
-
```ruby
|
134
|
-
action_item :view, only: :show do
|
135
|
-
link_to 'View on site', post_path(post) if post.published?
|
136
|
-
end
|
137
|
-
```
|
138
|
-
|
139
|
-
Actions items also accept the `:if` option to conditionally display them:
|
140
|
-
|
141
|
-
```ruby
|
142
|
-
action_item :super_action,
|
143
|
-
only: :show,
|
144
|
-
if: proc{ current_admin_user.super_admin? } do
|
145
|
-
"Only display this to super admins on the show screen"
|
146
|
-
end
|
147
|
-
```
|
148
|
-
|
149
|
-
By default action items are positioned in the same order as they defined (after default actions),
|
150
|
-
but it’s also possible to specify their position manually:
|
151
|
-
|
152
|
-
```ruby
|
153
|
-
action_item :help, priority: 0 do
|
154
|
-
"Display this action to the first position"
|
155
|
-
end
|
156
|
-
```
|
157
|
-
|
158
|
-
Default action item priority is 10.
|
159
|
-
|
160
|
-
# Modifying the Controller
|
161
|
-
|
162
|
-
The generated controller is available to you within the registration block by
|
163
|
-
using the `controller` method.
|
164
|
-
|
165
|
-
```ruby
|
166
|
-
ActiveAdmin.register Post do
|
167
|
-
|
168
|
-
controller do
|
169
|
-
# This code is evaluated within the controller class
|
170
|
-
|
171
|
-
def define_a_method
|
172
|
-
# Instance method
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
end
|
177
|
-
```
|