administrate 0.9.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/administrate/components/{has_many_form.js → associative.js} +1 -0
- data/app/assets/javascripts/administrate/components/date_time_picker.js +10 -2
- data/app/assets/javascripts/administrate/components/table.js +1 -1
- data/app/assets/stylesheets/administrate/base/_tables.scss +3 -0
- data/app/assets/stylesheets/administrate/base/_typography.scss +1 -1
- data/app/assets/stylesheets/administrate/components/_attributes.scss +1 -1
- data/app/assets/stylesheets/administrate/components/_buttons.scss +8 -0
- data/app/assets/stylesheets/administrate/components/_cells.scss +2 -0
- data/app/assets/stylesheets/administrate/components/_field-unit.scss +13 -4
- data/app/assets/stylesheets/administrate/components/_flashes.scss +0 -8
- data/app/assets/stylesheets/administrate/components/_navigation.scss +2 -3
- data/app/assets/stylesheets/administrate/library/_variables.scss +10 -8
- data/app/controllers/administrate/application_controller.rb +42 -13
- data/app/controllers/concerns/administrate/punditize.rb +3 -3
- data/app/helpers/administrate/application_helper.rb +59 -14
- data/app/views/administrate/application/_collection.html.erb +7 -6
- data/app/views/administrate/application/_flashes.html.erb +1 -1
- data/app/views/administrate/application/_form.html.erb +2 -2
- data/app/views/administrate/application/{_icons.erb → _icons.html.erb} +0 -0
- data/app/views/administrate/application/_navigation.html.erb +5 -3
- data/app/views/administrate/application/index.html.erb +2 -0
- data/app/views/administrate/application/show.html.erb +1 -1
- data/app/views/fields/belongs_to/_index.html.erb +1 -1
- data/app/views/fields/belongs_to/_show.html.erb +1 -1
- data/app/views/fields/date/_form.html.erb +24 -0
- data/app/views/fields/date/_index.html.erb +21 -0
- data/app/views/fields/date/_show.html.erb +21 -0
- data/app/views/fields/date_time/_form.html.erb +1 -1
- data/app/views/fields/date_time/_index.html.erb +1 -1
- data/app/views/fields/has_many/_form.html.erb +2 -2
- data/app/views/fields/has_many/_show.html.erb +8 -5
- data/app/views/fields/has_one/_form.html.erb +1 -1
- data/app/views/fields/password/_form.html.erb +23 -0
- data/app/views/fields/password/_index.html.erb +18 -0
- data/app/views/fields/password/_show.html.erb +18 -0
- data/app/views/fields/polymorphic/_form.html.erb +0 -3
- data/app/views/fields/select/_form.html.erb +22 -10
- data/app/views/fields/string/_show.html.erb +2 -2
- data/app/views/fields/text/_show.html.erb +2 -3
- data/app/views/fields/time/_form.html.erb +23 -0
- data/app/views/fields/time/_index.html.erb +17 -0
- data/app/views/fields/time/_show.html.erb +17 -0
- data/app/views/fields/url/_form.html.erb +23 -0
- data/app/views/fields/url/_index.html.erb +20 -0
- data/app/views/fields/url/_show.html.erb +20 -0
- data/app/views/layouts/administrate/application.html.erb +1 -1
- data/config/locales/administrate.ar.yml +2 -0
- data/config/locales/administrate.bs.yml +2 -0
- data/config/locales/administrate.ca.yml +2 -0
- data/config/locales/administrate.da.yml +2 -0
- data/config/locales/administrate.de.yml +2 -0
- data/config/locales/administrate.en.yml +2 -0
- data/config/locales/administrate.es.yml +3 -1
- data/config/locales/administrate.fr.yml +2 -0
- data/config/locales/administrate.id.yml +30 -0
- data/config/locales/administrate.it.yml +2 -0
- data/config/locales/administrate.ja.yml +4 -2
- data/config/locales/administrate.ko.yml +12 -10
- data/config/locales/administrate.nl.yml +3 -1
- data/config/locales/administrate.pl.yml +2 -0
- data/config/locales/administrate.pt-BR.yml +2 -0
- data/config/locales/administrate.pt.yml +2 -0
- data/config/locales/administrate.ru.yml +4 -2
- data/config/locales/administrate.sq.yml +30 -0
- data/config/locales/administrate.sv.yml +2 -0
- data/config/locales/administrate.uk.yml +2 -0
- data/config/locales/administrate.vi.yml +2 -0
- data/config/locales/administrate.zh-CN.yml +4 -2
- data/config/locales/administrate.zh-TW.yml +6 -4
- data/docs/adding_controllers_without_related_model.md +36 -0
- data/docs/adding_custom_field_types.md +3 -1
- data/docs/authentication.md +3 -1
- data/docs/authorization.md +5 -3
- data/docs/contributing.md +1 -0
- data/docs/customizing_attribute_partials.md +5 -2
- data/docs/customizing_controller_actions.md +32 -2
- data/docs/customizing_dashboards.md +103 -13
- data/docs/customizing_page_views.md +23 -5
- data/docs/getting_started.md +22 -51
- data/docs/rails_api.md +45 -0
- data/lib/administrate/base_dashboard.rb +33 -8
- data/lib/administrate/custom_dashboard.rb +15 -0
- data/lib/administrate/engine.rb +1 -1
- data/lib/administrate/field/associative.rb +5 -5
- data/lib/administrate/field/base.rb +13 -13
- data/lib/administrate/field/belongs_to.rb +3 -1
- data/lib/administrate/field/date.rb +20 -0
- data/lib/administrate/field/date_time.rb +1 -1
- data/lib/administrate/field/deferred.rb +19 -0
- data/lib/administrate/field/has_many.rb +16 -9
- data/lib/administrate/field/has_one.rb +7 -7
- data/lib/administrate/field/password.rb +25 -0
- data/lib/administrate/field/polymorphic.rb +6 -6
- data/lib/administrate/field/select.rb +6 -1
- data/lib/administrate/field/time.rb +8 -0
- data/lib/administrate/field/url.rb +21 -0
- data/lib/administrate/namespace.rb +5 -1
- data/lib/administrate/order.rb +17 -7
- data/lib/administrate/page/base.rb +9 -3
- data/lib/administrate/page/collection.rb +5 -1
- data/lib/administrate/page/form.rb +1 -1
- data/lib/administrate/search.rb +126 -11
- data/lib/administrate/version.rb +1 -1
- data/lib/administrate/view_generator.rb +2 -2
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +19 -6
- data/lib/generators/administrate/dashboard/templates/controller.rb.erb +33 -8
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +18 -6
- data/lib/generators/administrate/install/templates/application_controller.rb.erb +3 -3
- data/lib/generators/administrate/routes/routes_generator.rb +18 -13
- data/lib/generators/administrate/views/layout_generator.rb +1 -0
- metadata +47 -31
- data/config/secrets.yml +0 -14
@@ -0,0 +1 @@
|
|
1
|
+
../CONTRIBUTING.md
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
title: Customizing attribute partials
|
3
|
+
---
|
2
4
|
|
3
5
|
Occasionally you might want to change how specific types of attributes appear
|
4
6
|
across all dashboards. You can customize the following built in field types:
|
@@ -6,11 +8,12 @@ across all dashboards. You can customize the following built in field types:
|
|
6
8
|
- `belongs_to`
|
7
9
|
- `boolean`
|
8
10
|
- `date_time`
|
11
|
+
- `date`
|
9
12
|
- `email`
|
10
13
|
- `has_many`
|
11
14
|
- `has_one`
|
12
15
|
- `number`
|
13
|
-
- `
|
16
|
+
- `polymorphic`
|
14
17
|
- `select`
|
15
18
|
- `string`
|
16
19
|
- `text`
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
title: Customizing controller actions
|
3
|
+
---
|
2
4
|
|
3
5
|
When you install Administrate into your app,
|
4
6
|
we generate empty controllers for each of your resources.
|
@@ -28,9 +30,10 @@ class Admin::FoosController < Admin::ApplicationController
|
|
28
30
|
# def find_resource(param)
|
29
31
|
# Foo.find_by!(slug: param)
|
30
32
|
# end
|
31
|
-
|
33
|
+
|
32
34
|
# Override this if you have certain roles that require a subset
|
33
35
|
# this will be used to set the records shown on the `index` action.
|
36
|
+
#
|
34
37
|
# def scoped_resource
|
35
38
|
# if current_user.super_admin?
|
36
39
|
# resource_class
|
@@ -40,3 +43,30 @@ class Admin::FoosController < Admin::ApplicationController
|
|
40
43
|
# end
|
41
44
|
end
|
42
45
|
```
|
46
|
+
|
47
|
+
## Customizing Actions
|
48
|
+
|
49
|
+
To enable or disable certain actions you could override `valid_action?` method in your dashboard controller like this:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
# disable 'edit' and 'destroy' links
|
53
|
+
def valid_action?(name, resource = resource_class)
|
54
|
+
%w[edit destroy].exclude?(name.to_s) && super
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
Action is one of `new`, `edit`, `show`, `destroy`.
|
59
|
+
|
60
|
+
## Customizing Default Sorting
|
61
|
+
|
62
|
+
To set the default sorting on the index action you could override `default_sorting_attribute` or `default_sorting_direction` in your dashboard controller like this:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
def default_sorting_attribute
|
66
|
+
:age
|
67
|
+
end
|
68
|
+
|
69
|
+
def default_sorting_direction
|
70
|
+
:desc
|
71
|
+
end
|
72
|
+
```
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
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.
|
@@ -10,7 +12,7 @@ require "administrate/dashboard/base"
|
|
10
12
|
|
11
13
|
class CustomerDashboard < Administrate::Dashboard::Base
|
12
14
|
ATTRIBUTE_TYPES = {
|
13
|
-
id: Field::
|
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,7 @@ specify, including:
|
|
62
65
|
- `Field::Select`
|
63
66
|
- `Field::String`
|
64
67
|
- `Field::Text`
|
68
|
+
- `Field::Password`
|
65
69
|
|
66
70
|
## Customizing Fields
|
67
71
|
|
@@ -80,6 +84,30 @@ than one column. e.g.: `"name, email DESC"`.
|
|
80
84
|
`:foreign_key` - Specifies the name of the foreign key directly.
|
81
85
|
Defaults to `:#{attribute}_id`.
|
82
86
|
|
87
|
+
`:scope` - Specifies a custom scope inside a callable. Useful for preloading.
|
88
|
+
Example: `.with_options(scope: -> { MyModel.includes(:rel).limit(5) })`
|
89
|
+
|
90
|
+
`:class_name` - Specifies the name of the associated class.
|
91
|
+
Defaults to `:#{attribute}.to_s.singularize.camelcase`.
|
92
|
+
|
93
|
+
`:searchable` - Specify if the attribute should be considered when searching.
|
94
|
+
Default is `false`.
|
95
|
+
|
96
|
+
`searchable_fields` - Specify which columns to use on the search, only applies
|
97
|
+
if `searchable` is `true`
|
98
|
+
|
99
|
+
For example:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
country: Field::BelongsTo.with_options(
|
103
|
+
searchable: true,
|
104
|
+
searchable_fields: ['name'],
|
105
|
+
)
|
106
|
+
```
|
107
|
+
|
108
|
+
with this, you will be able to search through the column `name` from the
|
109
|
+
association `belongs_to :country`, from your model.
|
110
|
+
|
83
111
|
**Field::HasMany**
|
84
112
|
|
85
113
|
`:limit` - Set the number of resources to display in the show view. Default is
|
@@ -93,8 +121,38 @@ Defaults to `:#{attribute}_id`.
|
|
93
121
|
|
94
122
|
`:foreign_key` - Specifies the name of the foreign key directly. Defaults to `:#{attribute}_id`
|
95
123
|
|
124
|
+
`:class_name` - Specifies the name of the associated class.
|
125
|
+
Defaults to `:#{attribute}.to_s.singularize.camelcase`.
|
126
|
+
|
127
|
+
**Field::HasOne**
|
128
|
+
|
129
|
+
`:class_name` - Specifies the name of the associated class.
|
130
|
+
Defaults to `:#{attribute}.to_s.singularize.camelcase`.
|
131
|
+
|
132
|
+
`:searchable` - Specify if the attribute should be considered when searching.
|
133
|
+
Default is `false`.
|
134
|
+
|
135
|
+
`searchable_fields` - Specify which columns to use on the search, only applies if
|
136
|
+
`searchable` is `true`
|
137
|
+
|
138
|
+
For example:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
cities: Field::HasMany.with_options(
|
142
|
+
searchable: true,
|
143
|
+
searchable_fields: ['name'],
|
144
|
+
)
|
145
|
+
```
|
146
|
+
|
147
|
+
with this, you will be able to search through the column `name` from the
|
148
|
+
association `has_many :cities`, from your model.
|
149
|
+
|
96
150
|
**Field::Number**
|
97
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
|
+
|
98
156
|
`:decimals` - Set the number of decimals to display. Defaults to `0`.
|
99
157
|
|
100
158
|
`:prefix` - Prefixes the number with a string. Defaults to `""`.
|
@@ -135,9 +193,15 @@ objects to display as.
|
|
135
193
|
`:timezone` - Specify which timezone `Date` and `DateTime` objects are based
|
136
194
|
in.
|
137
195
|
|
196
|
+
**Field::Date**
|
197
|
+
|
198
|
+
`:format` - Specify what format, using `strftime` you would like `Date`
|
199
|
+
objects to display as.
|
200
|
+
|
138
201
|
**Field::Select**
|
139
202
|
|
140
|
-
`:collection` - Specify the
|
203
|
+
`:collection` - Specify the options shown on the select field. It accept either
|
204
|
+
an array or an object responding to `:call`. Defaults to `[]`.
|
141
205
|
|
142
206
|
`:searchable` - Specify if the attribute should be considered when searching.
|
143
207
|
Default is `true`.
|
@@ -158,6 +222,17 @@ Default is `false`.
|
|
158
222
|
`:truncate` - Set the number of characters to display in the index view.
|
159
223
|
Defaults to `50`.
|
160
224
|
|
225
|
+
**Field::Password**
|
226
|
+
|
227
|
+
`:searchable` - Specify if the attribute should be considered when searching.
|
228
|
+
Default is `false`.
|
229
|
+
|
230
|
+
`:truncate` - Set the number of characters to display in the views.
|
231
|
+
Defaults to `50`.
|
232
|
+
|
233
|
+
`:character` - Set the replace character.
|
234
|
+
Defaults to `•`.
|
235
|
+
|
161
236
|
### Defining Labels
|
162
237
|
|
163
238
|
To change the user-facing label for an attribute,
|
@@ -180,11 +255,11 @@ Add this method to the dashboard for Users.
|
|
180
255
|
Use whatever attribute or method you like.
|
181
256
|
Example for *user*:
|
182
257
|
|
183
|
-
|
258
|
+
```ruby
|
184
259
|
def display_resource(user)
|
185
260
|
user.name
|
186
261
|
end
|
187
|
-
|
262
|
+
```
|
188
263
|
|
189
264
|
[define your own]: /adding_custom_field_types
|
190
265
|
|
@@ -196,18 +271,33 @@ en:
|
|
196
271
|
models:
|
197
272
|
customer:
|
198
273
|
one: Happy Customer
|
199
|
-
|
274
|
+
other: Happy Customers
|
200
275
|
```
|
201
276
|
|
202
|
-
##
|
277
|
+
## Collection Filters
|
203
278
|
|
204
|
-
|
279
|
+
Resources can be filtered with pre-set filters. For example if we added:
|
205
280
|
|
206
281
|
```ruby
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
282
|
+
COLLECTION_FILTERS = {
|
283
|
+
inactive: ->(resources) { resources.where("login_at < ?", 1.week.ago) }
|
284
|
+
}
|
285
|
+
```
|
286
|
+
|
287
|
+
…to a dashboard, we can query the resources of that dashboard with:
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
bob inactive:
|
211
291
|
```
|
212
292
|
|
213
|
-
|
293
|
+
…to find users named "bob" who hasn't logged in the last week.
|
294
|
+
|
295
|
+
If you already had the `inactive` scope you could define the filter like so to
|
296
|
+
take advantage of existing ActiveRecord scopes (and other class methods on the
|
297
|
+
resource class).
|
298
|
+
|
299
|
+
```ruby
|
300
|
+
COLLECTION_FILTERS = {
|
301
|
+
inactive: ->(resources) { resources.inactive }
|
302
|
+
}
|
303
|
+
```
|
@@ -1,11 +1,25 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
title: Customizing page views
|
3
|
+
---
|
2
4
|
|
3
|
-
|
4
|
-
you can
|
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
|
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
|
```
|
data/docs/getting_started.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
title: Getting Started
|
3
|
+
---
|
2
4
|
|
3
5
|
Administrate is released as a Ruby gem, and can be installed on Rails
|
4
6
|
applications version 4.2 or greater.
|
@@ -37,11 +39,11 @@ Rails.application.routes.draw do
|
|
37
39
|
# Add dashboard for your models here
|
38
40
|
resources :customers,
|
39
41
|
resources :orders
|
40
|
-
|
42
|
+
|
41
43
|
root to: "customers#index" # <--- Root route
|
42
44
|
end
|
43
45
|
end
|
44
|
-
|
46
|
+
```
|
45
47
|
|
46
48
|
The routes can be customized to show or hide
|
47
49
|
different models on the dashboard.
|
@@ -73,10 +75,19 @@ namespace :admin do
|
|
73
75
|
end
|
74
76
|
```
|
75
77
|
|
78
|
+
## Using a Custom Namespace
|
79
|
+
|
80
|
+
Administrate supports using a namespace other than `Admin`, such as
|
81
|
+
`Supervisor`. This will also change the route it's using:
|
82
|
+
|
83
|
+
```sh
|
84
|
+
rails generate administrate:install --namespace=supervisor
|
85
|
+
```
|
86
|
+
|
76
87
|
## Keep Dashboards Updated as Model Attributes Change
|
77
88
|
|
78
|
-
If you've installed Administrate and generated dashboards and _then_
|
79
|
-
subsequently added attributes to your models you'll need to manually add
|
89
|
+
If you've installed Administrate and generated dashboards and _then_
|
90
|
+
subsequently added attributes to your models you'll need to manually add
|
80
91
|
these additions (or removals) to your dashboards.
|
81
92
|
|
82
93
|
Example:
|
@@ -89,7 +100,7 @@ Example:
|
|
89
100
|
the_new_attribute: Field::String,
|
90
101
|
# ...
|
91
102
|
}.freeze
|
92
|
-
|
103
|
+
|
93
104
|
SHOW_PAGE_ATTRIBUTES = [
|
94
105
|
# ...
|
95
106
|
:the_new_attribute,
|
@@ -101,7 +112,7 @@ Example:
|
|
101
112
|
:the_new_attribute,
|
102
113
|
# ...
|
103
114
|
].freeze
|
104
|
-
|
115
|
+
|
105
116
|
COLLECTION_ATTRIBUTES = [
|
106
117
|
# ...
|
107
118
|
:the_new_attribute, # if you want it on the index, also.
|
@@ -109,49 +120,9 @@ Example:
|
|
109
120
|
].freeze
|
110
121
|
```
|
111
122
|
|
112
|
-
It's recommended that you make this change at the same time as you add the
|
123
|
+
It's recommended that you make this change at the same time as you add the
|
113
124
|
attribute to the model.
|
114
125
|
|
115
|
-
The alternative way to handle this is to re-run `rails g administrate:install`
|
116
|
-
carefully pick through the diffs. This latter method is probably more
|
117
|
-
|
118
|
-
## Rails API
|
119
|
-
|
120
|
-
Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
|
121
|
-
we still want to have an admin.
|
122
|
-
|
123
|
-
To get this working, we recommend updating this config:
|
124
|
-
|
125
|
-
```ruby
|
126
|
-
# config/application.rb
|
127
|
-
config.api_only = false
|
128
|
-
```
|
129
|
-
|
130
|
-
That means, when your app _boots_, we'll have access to flashes and such. We
|
131
|
-
also don't use your `ApplicationController`. Instead, Administrate provides its
|
132
|
-
own. Meaning you're free to specify `ActionController::API` as your parent
|
133
|
-
controller to make sure no flash, session, or cookie middleware is used by your
|
134
|
-
API.
|
135
|
-
|
136
|
-
Alternatively, if your application needs to have `config.api_only = true`, we recommend you add the following lines to your `config/application.rb`
|
137
|
-
|
138
|
-
```ruby
|
139
|
-
# Enable Flash, Cookies, MethodOverride for Administrate Gem
|
140
|
-
config.middleware.use ActionDispatch::Flash
|
141
|
-
config.session_store :cookie_store
|
142
|
-
config.middleware.use ActionDispatch::Cookies
|
143
|
-
config.middleware.use ActionDispatch::Session::CookieStore, config.session_options
|
144
|
-
config.middleware.use ::Rack::MethodOverride
|
145
|
-
```
|
146
|
-
|
147
|
-
You must also ensure that the all the required controller actions are available and accessible as routes since generators in API-only applications only generate some of the required actions. Here is an example:
|
148
|
-
|
149
|
-
```ruby
|
150
|
-
# routes.rb
|
151
|
-
namespace :admin do
|
152
|
-
resources name, only: %i(index show new create edit update destroy)
|
153
|
-
end
|
154
|
-
|
155
|
-
# names_controller.rb
|
156
|
-
# Ensure each of those methods are defined
|
157
|
-
```
|
126
|
+
The alternative way to handle this is to re-run `rails g administrate:install`
|
127
|
+
and carefully pick through the diffs. This latter method is probably more
|
128
|
+
cumbersome.
|
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
|
+
```
|