activeadmin 2.6.1 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +438 -9
- data/CONTRIBUTING.md +12 -36
- data/README.md +8 -8
- data/app/assets/javascripts/active_admin/base.js +27 -25
- data/app/assets/stylesheets/active_admin/_base.scss +53 -37
- data/app/assets/stylesheets/active_admin/_forms.scss +2 -13
- data/app/assets/stylesheets/active_admin/_header.scss +37 -3
- data/app/assets/stylesheets/active_admin/_normalize.scss +25 -123
- data/app/assets/stylesheets/active_admin/components/_comments.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_date_picker.scss +1 -2
- data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +7 -5
- data/app/assets/stylesheets/active_admin/components/_pagination.scss +5 -2
- data/app/assets/stylesheets/active_admin/components/_table_tools.scss +9 -6
- data/app/assets/stylesheets/active_admin/components/_tabs.scss +10 -7
- data/app/assets/stylesheets/active_admin/mixins/_buttons.scss +2 -2
- data/app/assets/stylesheets/active_admin/mixins/_variables.scss +12 -0
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +6 -1
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +6 -4
- data/app/javascript/active_admin/initializers/has-many.js +4 -1
- data/app/javascript/active_admin/initializers/per-page.js +1 -1
- data/app/javascript/active_admin/lib/checkbox-toggler.js +3 -3
- data/app/javascript/active_admin/lib/dropdown-menu.js +1 -1
- data/app/javascript/active_admin/lib/modal-dialog.js +7 -7
- data/app/javascript/active_admin/lib/per-page.js +1 -1
- data/app/javascript/active_admin/lib/table-checkbox-toggler.js +1 -1
- data/app/views/active_admin/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/active_admin/devise/mailer/unlock_instructions.html.erb +2 -2
- data/app/views/active_admin/devise/shared/_links.erb +1 -1
- data/app/views/active_admin/page/index.html.arb +1 -0
- data/app/views/active_admin/resource/edit.html.arb +1 -0
- data/app/views/active_admin/resource/index.html.arb +1 -0
- data/app/views/active_admin/resource/new.html.arb +1 -0
- data/app/views/active_admin/resource/show.html.arb +1 -0
- data/app/views/layouts/active_admin.html.arb +1 -0
- data/app/views/layouts/active_admin_logged_out.html.erb +18 -7
- data/config/locales/ar.yml +6 -13
- data/config/locales/az.yml +0 -7
- data/config/locales/bg.yml +0 -7
- data/config/locales/bs.yml +0 -7
- data/config/locales/ca.yml +0 -7
- data/config/locales/cs.yml +0 -7
- data/config/locales/da.yml +0 -7
- data/config/locales/de-CH.yml +0 -7
- data/config/locales/de.yml +0 -8
- data/config/locales/el.yml +0 -7
- data/config/locales/en-CA.yml +0 -7
- data/config/locales/en-GB.yml +0 -7
- data/config/locales/en.yml +0 -8
- data/config/locales/eo.yml +0 -8
- data/config/locales/es-MX.yml +2 -8
- data/config/locales/es.yml +2 -10
- data/config/locales/fa.yml +0 -7
- data/config/locales/fi.yml +0 -7
- data/config/locales/fr.yml +3 -11
- data/config/locales/he.yml +0 -9
- data/config/locales/hr.yml +0 -7
- data/config/locales/hu.yml +0 -8
- data/config/locales/id.yml +0 -7
- data/config/locales/it.yml +18 -8
- data/config/locales/ja.yml +2 -10
- data/config/locales/ko.yml +1 -8
- data/config/locales/lt.yml +0 -8
- data/config/locales/lv.yml +0 -7
- data/config/locales/mk.yml +0 -8
- data/config/locales/nb.yml +0 -8
- data/config/locales/nl.yml +1 -9
- data/config/locales/pl.yml +0 -8
- data/config/locales/pt-BR.yml +0 -8
- data/config/locales/pt-PT.yml +0 -7
- data/config/locales/ro.yml +3 -9
- data/config/locales/ru.yml +0 -6
- data/config/locales/sk.yml +0 -8
- data/config/locales/sv-SE.yml +58 -39
- data/config/locales/tr.yml +0 -11
- data/config/locales/uk.yml +0 -6
- data/config/locales/vi.yml +38 -19
- data/config/locales/zh-CN.yml +34 -23
- data/config/locales/zh-TW.yml +0 -7
- data/lib/active_admin/abstract_view_factory.rb +1 -0
- data/lib/active_admin/application.rb +19 -19
- data/lib/active_admin/application_settings.rb +4 -3
- data/lib/active_admin/asset_registration.rb +4 -3
- data/lib/active_admin/authorization_adapter.rb +6 -3
- data/lib/active_admin/base_controller/authorization.rb +15 -13
- data/lib/active_admin/base_controller/menu.rb +1 -0
- data/lib/active_admin/base_controller.rb +6 -5
- data/lib/active_admin/batch_actions/controller.rb +4 -3
- data/lib/active_admin/batch_actions/resource_extension.rb +10 -8
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +4 -3
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +7 -6
- data/lib/active_admin/batch_actions/views/selection_cells.rb +4 -3
- data/lib/active_admin/batch_actions.rb +1 -0
- data/lib/active_admin/callbacks.rb +1 -0
- data/lib/active_admin/cancan_adapter.rb +2 -1
- data/lib/active_admin/collection_decorator.rb +32 -0
- data/lib/active_admin/component.rb +1 -0
- data/lib/active_admin/controller_action.rb +1 -0
- data/lib/active_admin/csv_builder.rb +25 -17
- data/lib/active_admin/dependency.rb +12 -15
- data/lib/active_admin/devise.rb +16 -5
- data/lib/active_admin/dsl.rb +2 -1
- data/lib/active_admin/dynamic_setting.rb +1 -0
- data/lib/active_admin/dynamic_settings_node.rb +3 -2
- data/lib/active_admin/engine.rb +17 -9
- data/lib/active_admin/error.rb +1 -2
- data/lib/active_admin/filters/active.rb +2 -1
- data/lib/active_admin/filters/active_filter.rb +6 -6
- data/lib/active_admin/filters/active_sidebar.rb +4 -30
- data/lib/active_admin/filters/dsl.rb +1 -0
- data/lib/active_admin/filters/forms.rb +9 -8
- data/lib/active_admin/filters/formtastic_addons.rb +3 -7
- data/lib/active_admin/filters/resource_extension.rb +6 -5
- data/lib/active_admin/filters.rb +8 -7
- data/lib/active_admin/form_builder.rb +25 -20
- data/lib/active_admin/generators/boilerplate.rb +2 -1
- data/lib/active_admin/helpers/collection.rb +2 -0
- data/lib/active_admin/helpers/i18n.rb +1 -0
- data/lib/active_admin/helpers/optional_display.rb +3 -2
- data/lib/active_admin/helpers/routes/url_helpers.rb +1 -0
- data/lib/active_admin/helpers/scope_chain.rb +1 -0
- data/lib/active_admin/inputs/datepicker_input.rb +2 -1
- data/lib/active_admin/inputs/filters/base/search_method_select.rb +7 -6
- data/lib/active_admin/inputs/filters/base.rb +2 -1
- data/lib/active_admin/inputs/filters/boolean_input.rb +2 -1
- data/lib/active_admin/inputs/filters/check_boxes_input.rb +2 -1
- data/lib/active_admin/inputs/filters/date_picker_input.rb +1 -0
- data/lib/active_admin/inputs/filters/date_range_input.rb +3 -2
- data/lib/active_admin/inputs/filters/numeric_input.rb +2 -1
- data/lib/active_admin/inputs/filters/select_input.rb +5 -2
- data/lib/active_admin/inputs/filters/string_input.rb +2 -1
- data/lib/active_admin/inputs/filters/text_input.rb +1 -0
- data/lib/active_admin/inputs.rb +1 -0
- data/lib/active_admin/localizers/resource_localizer.rb +4 -3
- data/lib/active_admin/localizers.rb +2 -1
- data/lib/active_admin/menu.rb +8 -3
- data/lib/active_admin/menu_collection.rb +1 -0
- data/lib/active_admin/menu_item.rb +8 -7
- data/lib/active_admin/namespace.rb +16 -15
- data/lib/active_admin/namespace_settings.rb +9 -5
- data/lib/active_admin/order_clause.rb +2 -1
- data/lib/active_admin/orm/active_record/comments/comment.rb +12 -3
- data/lib/active_admin/orm/active_record/comments/namespace_helper.rb +1 -0
- data/lib/active_admin/orm/active_record/comments/resource_helper.rb +1 -0
- data/lib/active_admin/orm/active_record/comments/show_page_helper.rb +1 -0
- data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +21 -20
- data/lib/active_admin/orm/active_record/comments/views.rb +3 -2
- data/lib/active_admin/orm/active_record/comments.rb +28 -27
- data/lib/active_admin/orm/active_record.rb +2 -1
- data/lib/active_admin/orm/mongoid.rb +1 -0
- data/lib/active_admin/page.rb +2 -1
- data/lib/active_admin/page_controller.rb +1 -0
- data/lib/active_admin/page_dsl.rb +1 -0
- data/lib/active_admin/page_presenter.rb +1 -0
- data/lib/active_admin/pundit_adapter.rb +58 -16
- data/lib/active_admin/resource/action_items.rb +6 -5
- data/lib/active_admin/resource/attributes.rb +9 -1
- data/lib/active_admin/resource/belongs_to.rb +3 -2
- data/lib/active_admin/resource/controllers.rb +2 -1
- data/lib/active_admin/resource/includes.rb +1 -0
- data/lib/active_admin/resource/menu.rb +5 -4
- data/lib/active_admin/resource/model.rb +1 -0
- data/lib/active_admin/resource/naming.rb +5 -4
- data/lib/active_admin/resource/ordering.rb +1 -0
- data/lib/active_admin/resource/page_presenters.rb +1 -0
- data/lib/active_admin/resource/pagination.rb +1 -0
- data/lib/active_admin/resource/routes.rb +6 -7
- data/lib/active_admin/resource/scope_to.rb +8 -7
- data/lib/active_admin/resource/scopes.rb +1 -0
- data/lib/active_admin/resource/sidebars.rb +2 -1
- data/lib/active_admin/resource.rb +20 -19
- data/lib/active_admin/resource_collection.rb +1 -0
- data/lib/active_admin/resource_controller/action_builder.rb +1 -0
- data/lib/active_admin/resource_controller/data_access.rb +31 -5
- data/lib/active_admin/resource_controller/decorators.rb +7 -28
- data/lib/active_admin/resource_controller/polymorphic_routes.rb +1 -0
- data/lib/active_admin/resource_controller/resource_class_methods.rb +1 -0
- data/lib/active_admin/resource_controller/scoping.rb +1 -0
- data/lib/active_admin/resource_controller/sidebars.rb +1 -0
- data/lib/active_admin/resource_controller/streaming.rb +9 -7
- data/lib/active_admin/resource_controller.rb +13 -11
- data/lib/active_admin/resource_dsl.rb +11 -25
- data/lib/active_admin/router.rb +1 -0
- data/lib/active_admin/scope.rb +7 -6
- data/lib/active_admin/settings_node.rb +1 -0
- data/lib/active_admin/sidebar_section.rb +1 -0
- data/lib/active_admin/version.rb +2 -1
- data/lib/active_admin/view_factory.rb +18 -17
- data/lib/active_admin/view_helpers/active_admin_application_helper.rb +1 -0
- data/lib/active_admin/view_helpers/auto_link_helper.rb +2 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +4 -3
- data/lib/active_admin/view_helpers/display_helper.rb +23 -8
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +2 -1
- data/lib/active_admin/view_helpers/fields_for.rb +3 -2
- data/lib/active_admin/view_helpers/flash_helper.rb +1 -0
- data/lib/active_admin/view_helpers/form_helper.rb +1 -0
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +1 -0
- data/lib/active_admin/view_helpers/scope_name_helper.rb +1 -0
- data/lib/active_admin/view_helpers/sidebar_helper.rb +1 -0
- data/lib/active_admin/view_helpers/title_helper.rb +1 -0
- data/lib/active_admin/view_helpers/view_factory_helper.rb +1 -0
- data/lib/active_admin/view_helpers.rb +2 -1
- data/lib/active_admin/views/action_items.rb +1 -0
- data/lib/active_admin/views/components/active_admin_form.rb +8 -11
- data/lib/active_admin/views/components/active_filters_sidebar_content.rb +59 -0
- data/lib/active_admin/views/components/attributes_table.rb +6 -5
- data/lib/active_admin/views/components/blank_slate.rb +2 -1
- data/lib/active_admin/views/components/columns.rb +1 -0
- data/lib/active_admin/views/components/dropdown_menu.rb +7 -9
- data/lib/active_admin/views/components/index_list.rb +4 -3
- data/lib/active_admin/views/components/menu.rb +2 -1
- data/lib/active_admin/views/components/menu_item.rb +5 -4
- data/lib/active_admin/views/components/paginated_collection.rb +19 -18
- data/lib/active_admin/views/components/panel.rb +2 -1
- data/lib/active_admin/views/components/scopes.rb +8 -5
- data/lib/active_admin/views/components/sidebar.rb +1 -0
- data/lib/active_admin/views/components/sidebar_section.rb +1 -0
- data/lib/active_admin/views/components/site_title.rb +2 -1
- data/lib/active_admin/views/components/status_tag.rb +12 -11
- data/lib/active_admin/views/components/table_for.rb +18 -17
- data/lib/active_admin/views/components/tabs.rb +4 -3
- data/lib/active_admin/views/components/unsupported_browser.rb +1 -0
- data/lib/active_admin/views/footer.rb +3 -1
- data/lib/active_admin/views/header.rb +3 -2
- data/lib/active_admin/views/index_as_block.rb +1 -0
- data/lib/active_admin/views/index_as_blog.rb +2 -1
- data/lib/active_admin/views/index_as_grid.rb +2 -1
- data/lib/active_admin/views/index_as_table.rb +16 -19
- data/lib/active_admin/views/pages/base.rb +17 -11
- data/lib/active_admin/views/pages/form.rb +1 -0
- data/lib/active_admin/views/pages/index.rb +15 -13
- data/lib/active_admin/views/pages/layout.rb +1 -0
- data/lib/active_admin/views/pages/page.rb +1 -0
- data/lib/active_admin/views/pages/show.rb +2 -7
- data/lib/active_admin/views/tabbed_navigation.rb +3 -2
- data/lib/active_admin/views/title_bar.rb +2 -1
- data/lib/active_admin/views.rb +2 -1
- data/lib/active_admin.rb +63 -61
- data/lib/activeadmin.rb +2 -1
- data/lib/generators/active_admin/assets/assets_generator.rb +3 -2
- data/lib/generators/active_admin/assets/templates/active_admin.scss +2 -2
- data/lib/generators/active_admin/devise/devise_generator.rb +6 -5
- data/lib/generators/active_admin/install/install_generator.rb +15 -8
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +27 -3
- data/lib/generators/active_admin/install/templates/dashboard.rb +1 -0
- data/lib/generators/active_admin/page/page_generator.rb +2 -1
- data/lib/generators/active_admin/page/templates/page.rb +1 -0
- data/lib/generators/active_admin/resource/resource_generator.rb +4 -3
- data/lib/generators/active_admin/webpacker/plugins/jquery.js +7 -0
- data/lib/generators/active_admin/webpacker/templates/active_admin.js +5 -0
- data/lib/generators/active_admin/webpacker/templates/active_admin.scss +17 -0
- data/lib/generators/active_admin/webpacker/templates/print.scss +2 -0
- data/lib/generators/active_admin/webpacker/webpacker_generator.rb +27 -0
- data/vendor/assets/javascripts/jquery-ui/data.js +12 -8
- data/vendor/assets/javascripts/jquery-ui/disable-selection.js +10 -7
- data/vendor/assets/javascripts/jquery-ui/focusable.js +12 -9
- data/vendor/assets/javascripts/jquery-ui/form-reset-mixin.js +60 -57
- data/vendor/assets/javascripts/jquery-ui/form.js +15 -12
- data/vendor/assets/javascripts/jquery-ui/ie.js +5 -2
- data/vendor/assets/javascripts/jquery-ui/keycode.js +11 -7
- data/vendor/assets/javascripts/jquery-ui/labels.js +46 -40
- data/vendor/assets/javascripts/jquery-ui/plugin.js +5 -2
- data/vendor/assets/javascripts/jquery-ui/position.js +30 -17
- data/vendor/assets/javascripts/jquery-ui/safe-active-element.js +6 -2
- data/vendor/assets/javascripts/jquery-ui/safe-blur.js +6 -2
- data/vendor/assets/javascripts/jquery-ui/scroll-parent.js +10 -7
- data/vendor/assets/javascripts/jquery-ui/tabbable.js +11 -8
- data/vendor/assets/javascripts/jquery-ui/unique-id.js +10 -7
- data/vendor/assets/javascripts/jquery-ui/version.js +6 -3
- data/vendor/assets/javascripts/jquery-ui/widget.js +53 -30
- data/vendor/assets/javascripts/jquery-ui/widgets/button.js +87 -24
- data/vendor/assets/javascripts/jquery-ui/widgets/checkboxradio.js +276 -273
- data/vendor/assets/javascripts/jquery-ui/widgets/controlgroup.js +15 -11
- data/vendor/assets/javascripts/jquery-ui/widgets/datepicker.js +182 -62
- data/vendor/assets/javascripts/jquery-ui/widgets/dialog.js +53 -36
- data/vendor/assets/javascripts/jquery-ui/widgets/draggable.js +28 -19
- data/vendor/assets/javascripts/jquery-ui/widgets/mouse.js +22 -11
- data/vendor/assets/javascripts/jquery-ui/widgets/resizable.js +47 -26
- data/vendor/assets/javascripts/jquery-ui/widgets/sortable.js +186 -125
- data/vendor/assets/javascripts/jquery-ui/widgets/tabs.js +20 -20
- metadata +48 -114
- data/docs/.gitignore +0 -1
- data/docs/0-installation.md +0 -118
- data/docs/1-general-configuration.md +0 -224
- data/docs/10-custom-pages.md +0 -150
- data/docs/11-decorators.md +0 -59
- 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 -466
- 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 -232
- data/docs/6-show-pages.md +0 -81
- 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 -3
- data/docs/Gemfile.lock +0 -248
- 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/lib/active_admin/deprecation.rb +0 -10
- data/lib/ransack_ext.rb +0 -20
- data/vendor/assets/javascripts/jquery-ui/escape-selector.js +0 -23
- /data/app/assets/stylesheets/active_admin/{print.scss → _print.scss} +0 -0
data/docs/5-forms.md
DELETED
@@ -1,232 +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
|
-
insert_tag active_admin_form_for 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 :comment,
|
114
|
-
new_record: 'Leave Comment',
|
115
|
-
allow_destroy: -> (c) { c.author?(current_admin_user) } do |b|
|
116
|
-
b.input :body
|
117
|
-
end
|
118
|
-
end
|
119
|
-
f.actions
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
```
|
124
|
-
|
125
|
-
*NOTE*: In addition to using `has_many` as illustrated above, you'll need to add
|
126
|
-
`accepts_nested_attributes` to your parent model and [configure strong parameters](https://activeadmin.info/2-resource-customization.html)
|
127
|
-
|
128
|
-
The `:allow_destroy` option adds a checkbox to the end of the nested form allowing
|
129
|
-
removal of the child object upon submission. Be sure to set `allow_destroy: true`
|
130
|
-
on the association to use this option. It is possible to associate
|
131
|
-
`:allow_destroy` with a string or a symbol, corresponding to the name of a child
|
132
|
-
object's method that will get called, or with a Proc object. The Proc object
|
133
|
-
receives the child object as a parameter and should return either true or false.
|
134
|
-
|
135
|
-
The `:heading` option adds a custom heading. You can hide it entirely by passing
|
136
|
-
`false`.
|
137
|
-
|
138
|
-
The `:new_record` option controls the visibility of the new record button (shown
|
139
|
-
by default). If you pass a string, it will be used as the text for the new
|
140
|
-
record button.
|
141
|
-
|
142
|
-
The `:sortable` option adds a hidden field and will enable drag & drop sorting
|
143
|
-
of the children. It expects the name of the column that will store the index of
|
144
|
-
each child.
|
145
|
-
|
146
|
-
The `:sortable_start` option sets the value (0 by default) of the first position
|
147
|
-
in the list.
|
148
|
-
|
149
|
-
## Datepicker
|
150
|
-
|
151
|
-
ActiveAdmin offers the `datepicker` input, which uses the [jQuery UI
|
152
|
-
datepicker](http://jqueryui.com/datepicker/). The datepicker input accepts any
|
153
|
-
of the options available to the standard jQueryUI Datepicker. For example:
|
154
|
-
|
155
|
-
```ruby
|
156
|
-
form do |f|
|
157
|
-
f.input :starts_at, as: :datepicker,
|
158
|
-
datepicker_options: {
|
159
|
-
min_date: "2013-10-8",
|
160
|
-
max_date: "+3D"
|
161
|
-
}
|
162
|
-
|
163
|
-
f.input :ends_at, as: :datepicker,
|
164
|
-
datepicker_options: {
|
165
|
-
min_date: 3.days.ago.to_date,
|
166
|
-
max_date: "+1W +5D"
|
167
|
-
}
|
168
|
-
end
|
169
|
-
```
|
170
|
-
|
171
|
-
Datepicker also accepts the `:label` option as a string or proc to display.
|
172
|
-
If it's a proc, it will be called each time the datepicker is rendered.
|
173
|
-
|
174
|
-
## Displaying Errors
|
175
|
-
|
176
|
-
To display a list of all validation errors:
|
177
|
-
|
178
|
-
```ruby
|
179
|
-
form do |f|
|
180
|
-
f.semantic_errors *f.object.errors.keys
|
181
|
-
# ...
|
182
|
-
end
|
183
|
-
```
|
184
|
-
|
185
|
-
This is particularly useful to display errors on virtual or hidden attributes.
|
186
|
-
|
187
|
-
# Tabs
|
188
|
-
|
189
|
-
You can arrange content in tabs as shown below:
|
190
|
-
|
191
|
-
```ruby
|
192
|
-
form do |f|
|
193
|
-
tabs do
|
194
|
-
tab 'Basic' do
|
195
|
-
f.inputs 'Basic Details' do
|
196
|
-
f.input :email
|
197
|
-
f.input :password
|
198
|
-
f.input :password_confirmation
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
tab 'Advanced', html_options: { class: 'specific_css_class' } do
|
203
|
-
f.inputs 'Advanced Details' do
|
204
|
-
f.input :role
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
f.actions
|
209
|
-
end
|
210
|
-
```
|
211
|
-
|
212
|
-
`html_options` allows you set additional html params for tab's menu item.
|
213
|
-
|
214
|
-
# Customize the Create Another checkbox
|
215
|
-
|
216
|
-
In order to simplify creating multiple resources you may enable ActiveAdmin to
|
217
|
-
show nice "Create Another" checkbox alongside of Create Model button. It may be
|
218
|
-
enabled for the whole application:
|
219
|
-
|
220
|
-
```ruby
|
221
|
-
ActiveAdmin.setup do |config|
|
222
|
-
config.create_another = true
|
223
|
-
end
|
224
|
-
```
|
225
|
-
|
226
|
-
or for the particular resource:
|
227
|
-
|
228
|
-
```ruby
|
229
|
-
ActiveAdmin.register Post do
|
230
|
-
config.create_another = true
|
231
|
-
end
|
232
|
-
```
|
data/docs/6-show-pages.md
DELETED
@@ -1,81 +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
|
-
```
|
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_attributes! 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
|
-
```
|