administrate 0.8.1 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +5 -5
  2. data/app/assets/javascripts/administrate/components/associative.js +5 -0
  3. data/app/assets/javascripts/administrate/components/date_time_picker.js +10 -2
  4. data/app/assets/javascripts/administrate/components/table.js +1 -1
  5. data/app/assets/stylesheets/administrate/base/_tables.scss +3 -0
  6. data/app/assets/stylesheets/administrate/base/_typography.scss +1 -1
  7. data/app/assets/stylesheets/administrate/components/_attributes.scss +4 -3
  8. data/app/assets/stylesheets/administrate/components/_buttons.scss +11 -0
  9. data/app/assets/stylesheets/administrate/components/_cells.scss +3 -5
  10. data/app/assets/stylesheets/administrate/components/_field-unit.scss +17 -4
  11. data/app/assets/stylesheets/administrate/components/_flashes.scss +0 -8
  12. data/app/assets/stylesheets/administrate/components/_main-content.scss +1 -0
  13. data/app/assets/stylesheets/administrate/components/_navigation.scss +2 -3
  14. data/app/assets/stylesheets/administrate/library/_variables.scss +10 -8
  15. data/app/assets/stylesheets/docs.scss +1 -0
  16. data/app/controllers/administrate/application_controller.rb +95 -21
  17. data/app/controllers/concerns/administrate/punditize.rb +36 -0
  18. data/app/helpers/administrate/application_helper.rb +51 -14
  19. data/app/views/administrate/application/_collection.html.erb +32 -33
  20. data/app/views/administrate/application/_collection_header_actions.html.erb +4 -0
  21. data/app/views/administrate/application/_collection_item_actions.html.erb +17 -0
  22. data/app/views/administrate/application/_flashes.html.erb +2 -1
  23. data/app/views/administrate/application/_form.html.erb +7 -4
  24. data/app/views/administrate/application/{_icons.erb → _icons.html.erb} +1 -1
  25. data/app/views/administrate/application/_index_header.html.erb +28 -0
  26. data/app/views/administrate/application/_navigation.html.erb +5 -3
  27. data/app/views/administrate/application/edit.html.erb +3 -3
  28. data/app/views/administrate/application/index.html.erb +11 -26
  29. data/app/views/administrate/application/new.html.erb +6 -1
  30. data/app/views/administrate/application/show.html.erb +5 -5
  31. data/app/views/fields/belongs_to/_form.html.erb +3 -3
  32. data/app/views/fields/belongs_to/_index.html.erb +1 -1
  33. data/app/views/fields/belongs_to/_show.html.erb +1 -1
  34. data/app/views/fields/date/_form.html.erb +24 -0
  35. data/app/views/fields/date/_index.html.erb +21 -0
  36. data/app/views/fields/date/_show.html.erb +21 -0
  37. data/app/views/fields/date_time/_form.html.erb +1 -1
  38. data/app/views/fields/date_time/_index.html.erb +1 -1
  39. data/app/views/fields/has_many/_form.html.erb +2 -2
  40. data/app/views/fields/has_many/_index.html.erb +1 -1
  41. data/app/views/fields/has_many/_show.html.erb +8 -5
  42. data/app/views/fields/has_one/_form.html.erb +1 -1
  43. data/app/views/fields/has_one/_index.html.erb +1 -1
  44. data/app/views/fields/has_one/_show.html.erb +4 -4
  45. data/app/views/fields/number/_form.html.erb +1 -1
  46. data/app/views/fields/password/_form.html.erb +23 -0
  47. data/app/views/fields/password/_index.html.erb +18 -0
  48. data/app/views/fields/password/_show.html.erb +18 -0
  49. data/app/views/fields/polymorphic/_form.html.erb +11 -9
  50. data/app/views/fields/polymorphic/_show.html.erb +8 -4
  51. data/app/views/fields/select/_form.html.erb +24 -10
  52. data/app/views/fields/string/_show.html.erb +2 -2
  53. data/app/views/fields/text/_show.html.erb +2 -3
  54. data/app/views/fields/time/_form.html.erb +23 -0
  55. data/app/views/fields/time/_index.html.erb +19 -0
  56. data/app/views/fields/time/_show.html.erb +19 -0
  57. data/app/views/fields/url/_form.html.erb +23 -0
  58. data/app/views/fields/url/_index.html.erb +20 -0
  59. data/app/views/fields/url/_show.html.erb +20 -0
  60. data/app/views/layouts/administrate/application.html.erb +2 -1
  61. data/config/locales/administrate.ar.yml +8 -6
  62. data/config/locales/administrate.bs.yml +29 -0
  63. data/config/locales/administrate.ca.yml +30 -0
  64. data/config/locales/administrate.da.yml +8 -6
  65. data/config/locales/administrate.de.yml +10 -8
  66. data/config/locales/administrate.en.yml +8 -6
  67. data/config/locales/administrate.es.yml +8 -6
  68. data/config/locales/administrate.fi.yml +30 -0
  69. data/config/locales/administrate.fr.yml +9 -7
  70. data/config/locales/administrate.id.yml +30 -0
  71. data/config/locales/administrate.it.yml +8 -6
  72. data/config/locales/administrate.ja.yml +8 -6
  73. data/config/locales/administrate.ko.yml +13 -11
  74. data/config/locales/administrate.nl.yml +12 -10
  75. data/config/locales/administrate.pl.yml +8 -6
  76. data/config/locales/administrate.pt-BR.yml +8 -6
  77. data/config/locales/administrate.pt.yml +8 -6
  78. data/config/locales/administrate.ru.yml +8 -6
  79. data/config/locales/administrate.sq.yml +30 -0
  80. data/config/locales/administrate.sv.yml +8 -6
  81. data/config/locales/administrate.tr.yml +30 -0
  82. data/config/locales/administrate.uk.yml +8 -6
  83. data/config/locales/administrate.vi.yml +8 -6
  84. data/config/locales/administrate.zh-CN.yml +8 -6
  85. data/config/locales/administrate.zh-TW.yml +10 -8
  86. data/config/unicorn.rb +8 -13
  87. data/docs/adding_controllers_without_related_model.md +52 -0
  88. data/docs/adding_custom_field_types.md +3 -1
  89. data/docs/authentication.md +3 -1
  90. data/docs/authorization.md +71 -0
  91. data/docs/customizing_attribute_partials.md +24 -2
  92. data/docs/customizing_controller_actions.md +50 -2
  93. data/docs/customizing_dashboards.md +210 -9
  94. data/docs/customizing_page_views.md +23 -5
  95. data/docs/extending_administrate.md +27 -0
  96. data/docs/getting_started.md +89 -15
  97. data/docs/guides/hiding_dashboards_from_sidebar.md +19 -0
  98. data/docs/guides.md +5 -0
  99. data/docs/rails_api.md +45 -0
  100. data/lib/administrate/base_dashboard.rb +53 -11
  101. data/lib/administrate/custom_dashboard.rb +15 -0
  102. data/lib/administrate/engine.rb +8 -1
  103. data/lib/administrate/field/associative.rb +55 -7
  104. data/lib/administrate/field/base.rb +35 -9
  105. data/lib/administrate/field/belongs_to.rb +18 -5
  106. data/lib/administrate/field/date.rb +20 -0
  107. data/lib/administrate/field/date_time.rb +13 -2
  108. data/lib/administrate/field/deferred.rb +29 -5
  109. data/lib/administrate/field/has_many.rb +32 -12
  110. data/lib/administrate/field/has_one.rb +39 -11
  111. data/lib/administrate/field/number.rb +19 -2
  112. data/lib/administrate/field/password.rb +25 -0
  113. data/lib/administrate/field/polymorphic.rb +42 -4
  114. data/lib/administrate/field/select.rb +10 -1
  115. data/lib/administrate/field/time.rb +19 -0
  116. data/lib/administrate/field/url.rb +21 -0
  117. data/lib/administrate/namespace.rb +6 -2
  118. data/lib/administrate/order.rb +52 -7
  119. data/lib/administrate/page/base.rb +9 -3
  120. data/lib/administrate/page/collection.rb +5 -1
  121. data/lib/administrate/page/form.rb +10 -3
  122. data/lib/administrate/resource_resolver.rb +4 -4
  123. data/lib/administrate/search.rb +138 -16
  124. data/lib/administrate/version.rb +1 -1
  125. data/lib/administrate/view_generator.rb +9 -3
  126. data/lib/administrate.rb +19 -0
  127. data/lib/generators/administrate/dashboard/USAGE +1 -1
  128. data/lib/generators/administrate/dashboard/dashboard_generator.rb +29 -17
  129. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +35 -10
  130. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +18 -6
  131. data/lib/generators/administrate/install/install_generator.rb +50 -7
  132. data/lib/generators/administrate/install/templates/{application_controller.rb → application_controller.rb.erb} +4 -4
  133. data/lib/generators/administrate/routes/routes_generator.rb +26 -26
  134. data/lib/generators/administrate/routes/templates/routes.rb.erb +1 -1
  135. data/lib/generators/administrate/views/field_generator.rb +19 -5
  136. data/lib/generators/administrate/views/layout_generator.rb +1 -0
  137. data/lib/generators/administrate/views/views_generator.rb +5 -4
  138. metadata +52 -53
  139. data/app/assets/javascripts/administrate/components/has_many_form.js +0 -3
  140. data/config/secrets.yml +0 -14
@@ -1,4 +1,6 @@
1
- # Customizing Dashboards
1
+ ---
2
+ title: Customizing Dashboards
3
+ ---
2
4
 
3
5
  In order to customize which attributes get displayed for each resource,
4
6
  edit the dashboard file generated by the installation generator.
@@ -6,11 +8,11 @@ edit the dashboard file generated by the installation generator.
6
8
  By default, the file will look something like this:
7
9
 
8
10
  ```ruby
9
- require "administrate/dashboard/base"
11
+ require "administrate/base_dashboard"
10
12
 
11
- class CustomerDashboard < Administrate::Dashboard::Base
13
+ class CustomerDashboard < Administrate::BaseDashboard
12
14
  ATTRIBUTE_TYPES = {
13
- id: Field::Integer,
15
+ id: Field::Number,
14
16
  name: Field::String,
15
17
  email: Field::String,
16
18
  created_at: Field::DateTime,
@@ -54,6 +56,7 @@ specify, including:
54
56
  - `Field::BelongsTo`
55
57
  - `Field::Boolean`
56
58
  - `Field::DateTime`
59
+ - `Field::Date`
57
60
  - `Field::Email`
58
61
  - `Field::HasMany`
59
62
  - `Field::HasOne`
@@ -62,6 +65,8 @@ specify, including:
62
65
  - `Field::Select`
63
66
  - `Field::String`
64
67
  - `Field::Text`
68
+ - `Field::Url`
69
+ - `Field::Password`
65
70
 
66
71
  ## Customizing Fields
67
72
 
@@ -70,6 +75,41 @@ specify, including:
70
75
  Each of the `Field` types take a different set of options,
71
76
  which are specified through the `.with_options` class method:
72
77
 
78
+ **Field::BelongsTo**
79
+
80
+ `:order` - Specifies the order of the dropdown menu, can be ordered by more
81
+ than one column. e.g.: `"name, email DESC"`.
82
+
83
+ `:scope` - Specifies a custom scope inside a callable. Useful for preloading.
84
+ Example: `.with_options(scope: -> { MyModel.includes(:rel).limit(5) })`
85
+
86
+ `:include_blank` - Specifies if the select element to be rendered should include
87
+ blank option. Default is `true`.
88
+
89
+ `:searchable` - Specify if the attribute should be considered when searching.
90
+ Default is `false`.
91
+
92
+ `searchable_fields` - Specify which columns to use on the search, only applies
93
+ if `searchable` is `true`
94
+
95
+ For example:
96
+
97
+ ```ruby
98
+ country: Field::BelongsTo.with_options(
99
+ searchable: true,
100
+ searchable_fields: ['name'],
101
+ )
102
+ ```
103
+
104
+ with this, you will be able to search through the column `name` from the
105
+ association `belongs_to :country`, from your model.
106
+
107
+ `:primary_key` (deprecated) - Specifies the association's primary_key.
108
+
109
+ `:foreign_key` (deprecated) - Specifies the name of the foreign key directly.
110
+
111
+ `:class_name` (deprecated) - Specifies the name of the associated class.
112
+
73
113
  **Field::HasMany**
74
114
 
75
115
  `:limit` - Set the number of resources to display in the show view. Default is
@@ -79,14 +119,53 @@ which are specified through the `.with_options` class method:
79
119
 
80
120
  `:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.
81
121
 
122
+ `:primary_key` (deprecated) - Specifies object's primary_key.
123
+
124
+ `:foreign_key` (deprecated) - Specifies the name of the foreign key directly.
125
+
126
+ `:class_name` (deprecated) - Specifies the name of the associated class.
127
+
128
+ **Field::HasOne**
129
+
130
+ `:searchable` - Specify if the attribute should be considered when searching.
131
+ Default is `false`.
132
+
133
+ `searchable_fields` - Specify which columns to use on the search, only applies if
134
+ `searchable` is `true`
135
+
136
+ For example:
137
+
138
+ ```ruby
139
+ cities: Field::HasMany.with_options(
140
+ searchable: true,
141
+ searchable_fields: ['name'],
142
+ )
143
+ ```
144
+
145
+ with this, you will be able to search through the column `name` from the
146
+ association `has_many :cities`, from your model.
147
+
148
+ `:class_name` (deprecated) - Specifies the name of the associated class.
149
+
82
150
  **Field::Number**
83
151
 
152
+ `:searchable` - Specify if the attribute should be considered when searching.
153
+ Note that currently number fields are searched like text, which may yield
154
+ more results than expected. Default is `false`.
155
+
84
156
  `:decimals` - Set the number of decimals to display. Defaults to `0`.
85
157
 
86
158
  `:prefix` - Prefixes the number with a string. Defaults to `""`.
87
159
 
88
160
  `:suffix` - Suffixes the number with a string. Defaults to `""`.
89
161
 
162
+ `:format` - Specify a hash which defines a formatter. This uses ActiveSupport
163
+ and works by by passing a hash that includes the formatter (`formatter`) and
164
+ the options for the formatter (`formatter_options`). Defaults to the locale's
165
+ delimiter when `formatter_options` does not include a `delimiter`. See the
166
+ example below. Note that currently only
167
+ `ActiveSupport::NumberHelper.number_to_delimited` is supported.
168
+
90
169
  For example, you might use the following to display U.S. currency:
91
170
 
92
171
  ```ruby
@@ -94,24 +173,59 @@ For example, you might use the following to display U.S. currency:
94
173
  prefix: "$",
95
174
  decimals: 2,
96
175
  )
176
+
177
+ # "$5.99"
97
178
  ```
98
179
 
99
- Or, to display a distance in kilometers:
180
+ Or, to display a distance in kilometers, using a space as the delimiter:
100
181
 
101
182
  ```ruby
102
- unit_price: Field::Number.with_options(
183
+ distance: Field::Number.with_options(
103
184
  suffix: " km",
104
185
  decimals: 2,
186
+ format: {
187
+ formatter: :number_to_delimited,
188
+ formatter_options: {
189
+ delimiter: ' ',
190
+ },
191
+ },
105
192
  )
193
+
194
+ # "2 000.00 km"
106
195
  ```
107
196
 
197
+ **Field::Polymorphic**
198
+
199
+ `:classes` - Specify a list of classes whose objects will be used to populate select boxes for editing this polymorphic field.
200
+ Default is `[]`.
201
+
202
+ `:order` - What to sort the association by in the form select.
203
+ Default is `nil`.
204
+
205
+ **Field::DateTime**
206
+
207
+ `:format` - Specify what format, using `strftime` you would like `DateTime`
208
+ objects to display as.
209
+
210
+ `:timezone` - Specify which timezone `Date` and `DateTime` objects are based
211
+ in.
212
+
213
+ **Field::Date**
214
+
215
+ `:format` - Specify what format, using `strftime` you would like `Date`
216
+ objects to display as.
217
+
108
218
  **Field::Select**
109
219
 
110
- `:collection` - Specify the array or range to select from. Defaults to `[]`.
220
+ `:collection` - Specify the options shown on the select field. It accept either
221
+ an array or an object responding to `:call`. Defaults to `[]`.
111
222
 
112
223
  `:searchable` - Specify if the attribute should be considered when searching.
113
224
  Default is `true`.
114
225
 
226
+ `:include_blank` - Specifies if the select element to be rendered should include
227
+ blank option. Default is `false`.
228
+
115
229
  **Field::String**
116
230
 
117
231
  `:searchable` - Specify if the attribute should be considered when searching.
@@ -128,6 +242,25 @@ Default is `false`.
128
242
  `:truncate` - Set the number of characters to display in the index view.
129
243
  Defaults to `50`.
130
244
 
245
+ **Field::Url**
246
+
247
+ `:searchable` - Specify if the attribute should be considered when searching.
248
+ Default is `true`.
249
+
250
+ `:truncate` - Set the number of characters to display in the index view.
251
+ Defaults to `50`.
252
+
253
+ **Field::Password**
254
+
255
+ `:searchable` - Specify if the attribute should be considered when searching.
256
+ Default is `false`.
257
+
258
+ `:truncate` - Set the number of characters to display in the views.
259
+ Defaults to `50`.
260
+
261
+ `:character` - Set the replace character.
262
+ Defaults to `•`.
263
+
131
264
  ### Defining Labels
132
265
 
133
266
  To change the user-facing label for an attribute,
@@ -150,10 +283,78 @@ Add this method to the dashboard for Users.
150
283
  Use whatever attribute or method you like.
151
284
  Example for *user*:
152
285
 
153
- ````ruby
286
+ ```ruby
154
287
  def display_resource(user)
155
288
  user.name
156
289
  end
157
- ````
290
+ ```
158
291
 
159
292
  [define your own]: /adding_custom_field_types
293
+
294
+ To change the dashboard name in sidebar menu, sub-header and search string use default ActiveRecord i18n translations for models:
295
+
296
+ ```yaml
297
+ en:
298
+ activerecord:
299
+ models:
300
+ customer:
301
+ one: Happy Customer
302
+ other: Happy Customers
303
+ ```
304
+
305
+ ## Collection Filters
306
+
307
+ Resources can be filtered with pre-set filters. For example if we added:
308
+
309
+ ```ruby
310
+ COLLECTION_FILTERS = {
311
+ inactive: ->(resources) { resources.where("login_at < ?", 1.week.ago) }
312
+ }
313
+ ```
314
+
315
+ …to a dashboard, we can query the resources of that dashboard with:
316
+
317
+ ```ruby
318
+ bob inactive:
319
+ ```
320
+
321
+ …to find users named "bob" who hasn't logged in the last week.
322
+
323
+ If you already had the `inactive` scope you could define the filter like so to
324
+ take advantage of existing ActiveRecord scopes (and other class methods on the
325
+ resource class).
326
+
327
+ ```ruby
328
+ COLLECTION_FILTERS = {
329
+ inactive: ->(resources) { resources.inactive }
330
+ }
331
+ ```
332
+
333
+ You can also define a filter with parameters:
334
+
335
+ ```ruby
336
+ COLLECTION_FILTERS = {
337
+ state: ->(resources, attr) { resources.where(state: attr) }
338
+ }
339
+ ```
340
+
341
+ You can now search your resource with 'state:open' and your
342
+ collection filter Proc will be called with with attr = open.
343
+
344
+ ## Form Attributes
345
+
346
+ You can define different attributes for new/create or edit/update actions:
347
+
348
+ ```ruby
349
+ FORM_ATTRIBUTES_NEW = [
350
+ :name,
351
+ :email
352
+ ]
353
+ FORM_ATTRIBUTES_EDIT = [
354
+ :name,
355
+ :email,
356
+ :orders
357
+ ]
358
+ ```
359
+
360
+ Or for custom action with constant name `"FORM_ATTRIBUTES_#{action.upcase}"`
@@ -1,11 +1,25 @@
1
- # Customizing page views
1
+ ---
2
+ title: Customizing page views
3
+ ---
2
4
 
3
- In order to change the appearance of any page,
4
- you can write custom Rails views.
5
+ You can provide replacements for any of Administrate's templates.
6
+ This way you can change the appearance of any page or element of
7
+ the interface.
8
+
9
+ In general, you can override any of the views under Administrate's
10
+ [/app/views][1].
11
+ For example, say that you want to customize the template used for flash
12
+ messages. You can provide your own as
13
+ `/app/views/administrate/application/_flashes.html.erb`, and it will replace
14
+ Administrate's own.
15
+
16
+ Figuring out which views are available and where can be repetitive. You can
17
+ spare yourself some effort by using the built-in view generators.
18
+
19
+ [1]: https://github.com/thoughtbot/administrate/tree/master/app/views
5
20
 
6
21
  ## Customizing for all resources
7
22
 
8
- The easiest way to get started is by using the built-in generators.
9
23
  In order to change the appearance of views for all resource types,
10
24
  call the generators with no arguments.
11
25
 
@@ -67,7 +81,7 @@ and will leave the show pages for other resources unchanged.
67
81
  ## Customizing layouts
68
82
 
69
83
  Many developers need to customize the layouts of their admin dashboard.
70
- It's so easy that pass in the "layout" key word to the view generators.
84
+ It's as easy as passing in the "layout" keyword to the view generators.
71
85
 
72
86
  ```bash
73
87
  rails generate administrate:views:layout
@@ -75,4 +89,8 @@ rails generate administrate:views:layout
75
89
  # -> app/views/admin/application/_navigation.html.erb
76
90
  # -> app/views/admin/application/_javascript.html.erb
77
91
  # -> app/views/admin/application/_flashes.html.erb
92
+
93
+ rails generate administrate:views:navigation
94
+ # It only generates the sidebar partial
95
+ # -> app/views/admin/application/_navigation.html.erb
78
96
  ```
@@ -0,0 +1,27 @@
1
+ ---
2
+ title: Extending Administrate
3
+ ---
4
+
5
+ Apart from the configuration described in these pages, it is possible to
6
+ extend Administrate's capabilities with the use of plugins. There are a
7
+ number of plugins available, many of which can be found at [RubyGems.org].
8
+ These are some popular examples:
9
+
10
+ 1. [ActiveStorage support](https://github.com/Dreamersoul/administrate-field-active_storage)
11
+ 2. [Enum field](https://github.com/Valiot/administrate-field-enum)
12
+ 3. [Nested has-many forms](https://github.com/nickcharlton/administrate-field-nested_has_many)
13
+ 4. [Belongs-to with Ajax search](https://github.com/fishbrain/administrate-field-belongs_to_search)
14
+ 5. [JSONb field plugin for Administrate](https://github.com/codica2/administrate-field-jsonb/)
15
+
16
+ See many more at https://rubygems.org/gems/administrate/reverse_dependencies.
17
+
18
+ Please note that these plugins are written by third parties. We do not
19
+ have any control over them, and we cannot give any assurances as to how
20
+ well they perform their advertised functions.
21
+
22
+ You can write your own plugins too! We don't document this specifically,
23
+ but you can have a look at the existing plugins for some directions.
24
+ In general, Administrate tries to abide by Rails's conventions, so that
25
+ hopefully should help!
26
+
27
+ [RubyGems.org]: https://rubygems.org
@@ -1,16 +1,18 @@
1
- # Getting Started
1
+ ---
2
+ title: Getting Started
3
+ ---
2
4
 
3
5
  Administrate is released as a Ruby gem, and can be installed on Rails
4
- applications version 4.2 or greater.
6
+ applications version 5.0 or greater. We support Ruby 2.6 and up.
5
7
 
6
- Add the following to your Gemfile:
8
+ First, add the following to your Gemfile:
7
9
 
8
10
  ```ruby
9
11
  # Gemfile
10
12
  gem "administrate"
11
13
  ```
12
14
 
13
- Re-bundle, then run the installer:
15
+ Re-bundle with `bundle install`, then run the installer:
14
16
 
15
17
  ```bash
16
18
  $ rails generate administrate:install
@@ -29,6 +31,20 @@ The `Admin::ApplicationController` can be customized to add
29
31
  authentication logic, authorization, pagination,
30
32
  or other controller-level concerns.
31
33
 
34
+ You will also want to add a `root` route to show a dashboard when you go to `/admin`.
35
+
36
+ ```ruby
37
+ Rails.application.routes.draw do
38
+ namespace :admin do
39
+ # Add dashboard for your models here
40
+ resources :customers
41
+ resources :orders
42
+
43
+ root to: "customers#index" # <--- Root route
44
+ end
45
+ end
46
+ ```
47
+
32
48
  The routes can be customized to show or hide
33
49
  different models on the dashboard.
34
50
 
@@ -40,6 +56,28 @@ Each `Admin::FooController` can be overwritten to specify custom behavior.
40
56
  Once you have Administrate installed,
41
57
  visit <http://localhost:3000/admin> to see your new dashboard in action.
42
58
 
59
+ ### Errors about assets?
60
+
61
+ If your apps uses Sprockets 4, you'll need to add Administrate's assets to
62
+ your `manifest.js` file. To do this, add these two lines to the file:
63
+
64
+ ```
65
+ //= link administrate/application.css
66
+ //= link administrate/application.js
67
+ ```
68
+
69
+ Otherwise, your app will show you this error:
70
+
71
+ ```
72
+ Asset `administrate/application.css` was not declared to be precompiled in production.
73
+ Declare links to your assets in `app/assets/config/manifest.js`.
74
+ ```
75
+
76
+ For more information on why this is necessary, see Richard Schneeman's article
77
+ ["Self Hosted Config: Introducing the Sprockets manifest.js"][]
78
+
79
+ [schneems]: https://www.schneems.com/2017/11/22/self-hosted-config-introducing-the-sprockets-manifestjs
80
+
43
81
  ## Create Additional Dashboards
44
82
 
45
83
  In order to create additional dashboards, pass in the resource name to
@@ -49,7 +87,7 @@ the dashboard generator. A dashboard and controller will be created.
49
87
  $ rails generate administrate:dashboard Foo
50
88
  ```
51
89
 
52
- Add a route for the new dashboard.
90
+ Then add a route for the new dashboard.
53
91
 
54
92
  ```ruby
55
93
  # config/routes.rb
@@ -59,18 +97,54 @@ namespace :admin do
59
97
  end
60
98
  ```
61
99
 
62
- ## Rails API
100
+ ## Using a Custom Namespace
101
+
102
+ Administrate supports using a namespace other than `Admin`, such as
103
+ `Supervisor`. This will also change the route it's using:
104
+
105
+ ```sh
106
+ rails generate administrate:install --namespace=supervisor
107
+ ```
108
+
109
+ ## Keep Dashboards Updated as Model Attributes Change
63
110
 
64
- Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
65
- we still want to have an admin. To get this working, please update this config:
111
+ If you've installed Administrate and generated dashboards and _then_
112
+ subsequently added attributes to your models you'll need to manually add
113
+ these additions (or removals) to your dashboards.
114
+
115
+ Example:
66
116
 
67
117
  ```ruby
68
- # config/application.rb
69
- config.api_only = false
118
+ # app/dashboards/your_model_dashboard.rb
119
+
120
+ ATTRIBUTE_TYPES = {
121
+ # ...
122
+ the_new_attribute: Field::String,
123
+ # ...
124
+ }.freeze
125
+
126
+ SHOW_PAGE_ATTRIBUTES = [
127
+ # ...
128
+ :the_new_attribute,
129
+ # ...
130
+ ].freeze
131
+
132
+ FORM_ATTRIBUTES = [
133
+ # ...
134
+ :the_new_attribute,
135
+ # ...
136
+ ].freeze
137
+
138
+ COLLECTION_ATTRIBUTES = [
139
+ # ...
140
+ :the_new_attribute, # if you want it on the index, also.
141
+ # ...
142
+ ].freeze
70
143
  ```
71
144
 
72
- That means, when your app _boots_, we'll have access to flashes and such. We
73
- also don't use your `ApplicationController`. Instead, Administrate provides its
74
- own. Meaning you're free to specify `ActionController::API` as your parent
75
- controller to make sure no flash, session, or cookie middleware is used by your
76
- API.
145
+ It's recommended that you make this change at the same time as you add the
146
+ attribute to the model.
147
+
148
+ The alternative way to handle this is to re-run `rails g administrate:install`
149
+ and carefully pick through the diffs. This latter method is probably more
150
+ cumbersome.
@@ -0,0 +1,19 @@
1
+ ---
2
+ title: Hiding Dashboards from the Sidebar
3
+ ---
4
+
5
+ Resources can be removed form the sidebar by removing their index action from the routes. For example:
6
+
7
+ ```ruby
8
+ # config/routes.rb
9
+ Rails.application.routes.draw do
10
+ namespace :admin do
11
+ resources :line_items, except: :index
12
+ resources :orders
13
+ resources :products
14
+ root to: "customers#index"
15
+ end
16
+ end
17
+ ```
18
+
19
+ In this case, only Orders and Products will appear in the sidebar, while Line Items can still appear as an association.
data/docs/guides.md ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Guides
3
+ ---
4
+
5
+ * [Hiding Dashboards from the Sidebar](./guides/hiding_dashboards_from_sidebar)
data/docs/rails_api.md ADDED
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: Rails API
3
+ ---
4
+
5
+ Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
6
+ we still want to have an admin.
7
+
8
+ To get this working, we recommend updating this config:
9
+
10
+ ```ruby
11
+ # config/application.rb
12
+ config.api_only = false
13
+ ```
14
+
15
+ That means, when your app _boots_, we'll have access to flashes and such. We
16
+ also don't use your `ApplicationController`. Instead, Administrate provides its
17
+ own. Meaning you're free to specify `ActionController::API` as your parent
18
+ controller to make sure no flash, session, or cookie middleware is used by your
19
+ API.
20
+
21
+ Alternatively, if your application needs to have `config.api_only = true`, we
22
+ recommend you add the following lines to your `config/application.rb`
23
+
24
+ ```ruby
25
+ # Enable Flash, Cookies, MethodOverride for Administrate Gem
26
+ config.middleware.use ActionDispatch::Flash
27
+ config.session_store :cookie_store
28
+ config.middleware.use ActionDispatch::Cookies
29
+ config.middleware.use ActionDispatch::Session::CookieStore, config.session_options
30
+ config.middleware.use ::Rack::MethodOverride
31
+ ```
32
+
33
+ You must also ensure that all the required controller actions are available
34
+ and accessible as routes since generators in API-only applications only
35
+ generate some of the required actions. Here is an example:
36
+
37
+ ```ruby
38
+ # routes.rb
39
+ namespace :admin do
40
+ resources :name, only: %i(index show new create edit update destroy)
41
+ end
42
+
43
+ # names_controller.rb
44
+ # Ensure each of those methods are defined
45
+ ```