administrate 0.12.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/administrate/components/associative.js +5 -0
  3. data/app/assets/javascripts/administrate/components/date_time_picker.js +6 -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/components/_attributes.scss +4 -3
  7. data/app/assets/stylesheets/administrate/components/_buttons.scss +11 -0
  8. data/app/assets/stylesheets/administrate/components/_cells.scss +2 -0
  9. data/app/assets/stylesheets/administrate/components/_field-unit.scss +17 -4
  10. data/app/assets/stylesheets/administrate/components/_flashes.scss +0 -8
  11. data/app/assets/stylesheets/administrate/components/_main-content.scss +1 -0
  12. data/app/assets/stylesheets/administrate/components/_navigation.scss +2 -3
  13. data/app/assets/stylesheets/administrate/library/_variables.scss +10 -8
  14. data/app/controllers/administrate/application_controller.rb +47 -13
  15. data/app/helpers/administrate/application_helper.rb +32 -14
  16. data/app/views/administrate/application/_collection.html.erb +24 -26
  17. data/app/views/administrate/application/_collection_header_actions.html.erb +4 -0
  18. data/app/views/administrate/application/_collection_item_actions.html.erb +17 -0
  19. data/app/views/administrate/application/_flashes.html.erb +1 -0
  20. data/app/views/administrate/application/_form.html.erb +3 -3
  21. data/app/views/administrate/application/_icons.html.erb +1 -1
  22. data/app/views/administrate/application/_index_header.html.erb +28 -0
  23. data/app/views/administrate/application/_navigation.html.erb +5 -3
  24. data/app/views/administrate/application/index.html.erb +9 -29
  25. data/app/views/administrate/application/show.html.erb +1 -1
  26. data/app/views/fields/belongs_to/_form.html.erb +3 -3
  27. data/app/views/fields/belongs_to/_index.html.erb +1 -1
  28. data/app/views/fields/belongs_to/_show.html.erb +1 -1
  29. data/app/views/fields/date/_form.html.erb +24 -0
  30. data/app/views/fields/date/_index.html.erb +21 -0
  31. data/app/views/fields/date/_show.html.erb +21 -0
  32. data/app/views/fields/has_one/_index.html.erb +1 -1
  33. data/app/views/fields/has_one/_show.html.erb +4 -4
  34. data/app/views/fields/number/_form.html.erb +1 -1
  35. data/app/views/fields/polymorphic/_show.html.erb +1 -1
  36. data/app/views/fields/select/_form.html.erb +23 -9
  37. data/app/views/fields/string/_show.html.erb +2 -2
  38. data/app/views/fields/text/_show.html.erb +2 -3
  39. data/app/views/fields/time/_form.html.erb +3 -2
  40. data/app/views/fields/time/_index.html.erb +3 -1
  41. data/app/views/fields/time/_show.html.erb +3 -1
  42. data/app/views/fields/url/_index.html.erb +1 -1
  43. data/app/views/fields/url/_show.html.erb +1 -1
  44. data/app/views/layouts/administrate/application.html.erb +1 -0
  45. data/config/locales/administrate.ar.yml +2 -0
  46. data/config/locales/administrate.bs.yml +2 -0
  47. data/config/locales/administrate.ca.yml +2 -0
  48. data/config/locales/administrate.da.yml +2 -0
  49. data/config/locales/administrate.de.yml +2 -0
  50. data/config/locales/administrate.en.yml +2 -0
  51. data/config/locales/administrate.es.yml +2 -0
  52. data/config/locales/administrate.fi.yml +30 -0
  53. data/config/locales/administrate.fr.yml +4 -2
  54. data/config/locales/administrate.id.yml +2 -0
  55. data/config/locales/administrate.it.yml +2 -0
  56. data/config/locales/administrate.ja.yml +2 -0
  57. data/config/locales/administrate.ko.yml +2 -0
  58. data/config/locales/administrate.nl.yml +7 -5
  59. data/config/locales/administrate.pl.yml +2 -0
  60. data/config/locales/administrate.pt-BR.yml +4 -2
  61. data/config/locales/administrate.pt.yml +4 -2
  62. data/config/locales/administrate.ru.yml +2 -0
  63. data/config/locales/{administrate.al.yml → administrate.sq.yml} +3 -1
  64. data/config/locales/administrate.sv.yml +2 -0
  65. data/config/locales/administrate.tr.yml +30 -0
  66. data/config/locales/administrate.uk.yml +2 -0
  67. data/config/locales/administrate.vi.yml +2 -0
  68. data/config/locales/administrate.zh-CN.yml +2 -0
  69. data/config/locales/administrate.zh-TW.yml +2 -0
  70. data/config/unicorn.rb +8 -13
  71. data/docs/adding_controllers_without_related_model.md +52 -0
  72. data/docs/adding_custom_field_types.md +3 -1
  73. data/docs/authentication.md +3 -1
  74. data/docs/authorization.md +5 -3
  75. data/docs/customizing_attribute_partials.md +4 -1
  76. data/docs/customizing_controller_actions.md +48 -1
  77. data/docs/customizing_dashboards.md +90 -37
  78. data/docs/customizing_page_views.md +18 -4
  79. data/docs/extending_administrate.md +27 -0
  80. data/docs/getting_started.md +35 -11
  81. data/docs/guides/hiding_dashboards_from_sidebar.md +19 -0
  82. data/docs/guides.md +5 -0
  83. data/docs/rails_api.md +5 -3
  84. data/lib/administrate/base_dashboard.rb +35 -12
  85. data/lib/administrate/custom_dashboard.rb +15 -0
  86. data/lib/administrate/engine.rb +7 -0
  87. data/lib/administrate/field/associative.rb +49 -5
  88. data/lib/administrate/field/base.rb +35 -9
  89. data/lib/administrate/field/belongs_to.rb +13 -3
  90. data/lib/administrate/field/date.rb +20 -0
  91. data/lib/administrate/field/deferred.rb +22 -3
  92. data/lib/administrate/field/has_many.rb +15 -2
  93. data/lib/administrate/field/has_one.rb +32 -12
  94. data/lib/administrate/field/number.rb +19 -2
  95. data/lib/administrate/field/polymorphic.rb +5 -5
  96. data/lib/administrate/field/select.rb +10 -1
  97. data/lib/administrate/field/time.rb +11 -0
  98. data/lib/administrate/namespace.rb +5 -1
  99. data/lib/administrate/order.rb +17 -7
  100. data/lib/administrate/page/base.rb +1 -3
  101. data/lib/administrate/page/form.rb +10 -3
  102. data/lib/administrate/resource_resolver.rb +2 -2
  103. data/lib/administrate/search.rb +47 -36
  104. data/lib/administrate/version.rb +1 -1
  105. data/lib/administrate/view_generator.rb +9 -3
  106. data/lib/administrate.rb +19 -0
  107. data/lib/generators/administrate/dashboard/dashboard_generator.rb +19 -15
  108. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +22 -10
  109. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +4 -4
  110. data/lib/generators/administrate/install/install_generator.rb +37 -1
  111. data/lib/generators/administrate/install/templates/application_controller.rb.erb +4 -4
  112. data/lib/generators/administrate/routes/routes_generator.rb +15 -25
  113. data/lib/generators/administrate/views/views_generator.rb +5 -4
  114. metadata +29 -43
  115. data/app/assets/javascripts/administrate/components/has_many_form.js +0 -3
@@ -0,0 +1,30 @@
1
+ ---
2
+ tr:
3
+ administrate:
4
+ actions:
5
+ confirm: Emin misiniz?
6
+ destroy: Sil
7
+ edit: Düzenle
8
+ edit_resource: "%{name} Kaydını Düzenle"
9
+ show_resource: "%{name} Kaydını Göster"
10
+ new_resource: Yeni %{name}
11
+ back: Geri
12
+ controller:
13
+ create:
14
+ success: "%{resource} kaydı başarıyla yaratıldı."
15
+ destroy:
16
+ success: "%{resource} kaydı başarıyla silindi."
17
+ update:
18
+ success: "%{resource} kaydı başarıyla düzenlendi."
19
+ fields:
20
+ has_many:
21
+ more: Toplam %{total_count} kayıttan %{count} adedi gösteriliyor
22
+ none: Yok
23
+ form:
24
+ error: Hata
25
+ errors: "%{resource_name} kaydedilemedi: %{pluralized_errors}"
26
+ navigation:
27
+ back_to_app: Uygulamaya geri dön
28
+ search:
29
+ clear: Temizle
30
+ label: "%{resource} içerisinde ara"
@@ -23,6 +23,8 @@ uk:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Повернутися до програми
26
28
  search:
27
29
  clear: Очистити пошук
28
30
  label: пошук %{resource}
@@ -23,6 +23,8 @@ vi:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Quay lại ứng dụng
26
28
  search:
27
29
  clear: Tìm kiếm rõ ràng
28
30
  label: Tìm kiếm %{resource}
@@ -23,6 +23,8 @@ zh-CN:
23
23
  form:
24
24
  error: 错误
25
25
  errors: "%{resource_name} 保存前出现了 %{pluralized_errors} 个错误:"
26
+ navigation:
27
+ back_to_app: 返回应用
26
28
  search:
27
29
  clear: 清除搜索
28
30
  label: 搜索 %{resource}
@@ -23,6 +23,8 @@ zh-TW:
23
23
  form:
24
24
  error: 錯誤
25
25
  errors: "%{pluralized_errors} 導致此 %{resource_name} 不能被儲存:"
26
+ navigation:
27
+ back_to_app: 返回首頁
26
28
  search:
27
29
  clear: 清除搜尋
28
30
  label: 搜尋 %{resource}
data/config/unicorn.rb CHANGED
@@ -1,30 +1,25 @@
1
1
  # https://devcenter.heroku.com/articles/rails-unicorn
2
2
 
3
- worker_processes (ENV["UNICORN_WORKERS"] || 3).to_i
4
- timeout (ENV["UNICORN_TIMEOUT"] || 15).to_i
3
+ worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
4
+ timeout 15
5
5
  preload_app true
6
6
 
7
7
  before_fork do |_server, _worker|
8
8
  Signal.trap "TERM" do
9
- puts "Unicorn master intercepting TERM, sending myself QUIT instead"
9
+ puts "Unicorn master intercepting TERM and sending myself QUIT instead"
10
10
  Process.kill "QUIT", Process.pid
11
11
  end
12
12
 
13
- if defined? ActiveRecord::Base
13
+ defined?(ActiveRecord::Base) &&
14
14
  ActiveRecord::Base.connection.disconnect!
15
- end
16
15
  end
17
16
 
18
17
  after_fork do |_server, _worker|
19
18
  Signal.trap "TERM" do
20
- puts "Unicorn worker intercepting TERM, waiting for master to send QUIT"
19
+ puts "Unicorn worker intercepting TERM and doing nothing. " \
20
+ "Wait for master to send QUIT"
21
21
  end
22
22
 
23
- if defined? ActiveRecord::Base
24
- config = ActiveRecord::Base.configurations[Rails.env] ||
25
- Rails.application.config.database_configuration[Rails.env]
26
- config["reaping_frequency"] = (ENV["DB_REAPING_FREQUENCY"] || 10).to_i
27
- config["pool"] = (ENV["DB_POOL"] || 2).to_i
28
- ActiveRecord::Base.establish_connection(config)
29
- end
23
+ defined?(ActiveRecord::Base) &&
24
+ ActiveRecord::Base.establish_connection
30
25
  end
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: Adding Controllers without a related Model
3
+ ---
4
+
5
+ Sometimes you may want to add a custom controller that has no resource
6
+ related to it (for example for a statistics page).
7
+
8
+ To do that, you must define an `index` route, as only controllers with index
9
+ routes are displayed in the sidebar and then add a custom dashboard:
10
+
11
+ ```erb
12
+ # app/views/admin/stats/index.html.erb
13
+
14
+ <div style="padding: 20px">
15
+ <h1>Stats</h1>
16
+ <br>
17
+ <p><b>Total Customers:</b> <%= @stats[:customer_count] %></h1>
18
+ <br>
19
+ <p><b>Total Orders:</b> <%= @stats[:order_count] %></h1>
20
+ </div>
21
+ ```
22
+
23
+ ```ruby
24
+ # app/dashboards/stat_dashboard.rb
25
+ require "administrate/custom_dashboard"
26
+
27
+ class StatDashboard < Administrate::CustomDashboard
28
+ resource "Stats" # used by administrate in the views
29
+ end
30
+ ```
31
+
32
+ ```ruby
33
+ # app/controllers/admin/stats_controller.rb
34
+ module Admin
35
+ class StatsController < Admin::ApplicationController
36
+ def index
37
+ @stats = {
38
+ customer_count: Customer.count,
39
+ order_count: Order.count,
40
+ }
41
+ end
42
+ end
43
+ end
44
+ ```
45
+
46
+ ```ruby
47
+ # config/routes.rb
48
+ namespace :admin do
49
+ # ...
50
+ resources :stats, only: [:index]
51
+ end
52
+ ```
@@ -1,4 +1,6 @@
1
- # Adding Custom Field Types
1
+ ---
2
+ title: Adding Custom Field Types
3
+ ---
2
4
 
3
5
  If your application deals with a nonstandard data type,
4
6
  you can create an `Administrate::Field` object to help display
@@ -1,4 +1,6 @@
1
- # Authenticating admin users
1
+ ---
2
+ title: Authenticating admin users
3
+ ---
2
4
 
3
5
  Authentication is left for you to implement after you install Administrate into
4
6
  your app. It's expected that you can plugin your existing authentication
@@ -1,4 +1,6 @@
1
- # Authorization
1
+ ---
2
+ title: Authorization
3
+ ---
2
4
 
3
5
  The default configuration of Administrate is "authenticate-only" - once a
4
6
  user is authenticated, that user has access to every action of every object.
@@ -37,7 +39,7 @@ class PostPolicy < ApplicationPolicy
37
39
  def resolve
38
40
  scope.all
39
41
  end
40
-
42
+
41
43
  def resolve_admin
42
44
  scope.where(owner: user)
43
45
  end
@@ -62,7 +64,7 @@ def authorize_resource(resource)
62
64
  raise "Erg!" unless show_action?(params[:action], resource)
63
65
  end
64
66
 
65
- # Hide links to actions if the user is not allowed to do them
67
+ # Hide links to actions if the user is not allowed to do them
66
68
  def show_action?(action, resource)
67
69
  current_user.can? action, resource
68
70
  end
@@ -1,4 +1,6 @@
1
- # Customizing attribute partials
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,6 +8,7 @@ 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`
@@ -1,4 +1,6 @@
1
- # Customizing controller actions
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.
@@ -41,3 +43,48 @@ class Admin::FoosController < Admin::ApplicationController
41
43
  # end
42
44
  end
43
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
+ ```
73
+
74
+ ## Customizing Redirects after actions
75
+
76
+ To set custom redirects after the actions `create`, `update` and `destroy` you can override `after_resource_created_path`, `after_resource_updated_path` or `after_resource_destroyed_path` like this:
77
+
78
+ ```ruby
79
+ def after_resource_destroyed_path(_requested_resource)
80
+ { action: :index, controller: :some_other_resource }
81
+ end
82
+
83
+ def after_resource_created_path(requested_resource)
84
+ [namespace, requested_resource.some_other_resource]
85
+ end
86
+
87
+ def after_resource_updated_path(requested_resource)
88
+ [namespace, requested_resource.some_other_resource]
89
+ end
90
+ ```
@@ -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,9 +8,9 @@ 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
15
  id: Field::Number,
14
16
  name: Field::String,
@@ -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::Url`
65
69
  - `Field::Password`
66
70
 
67
71
  ## Customizing Fields
@@ -76,21 +80,16 @@ which are specified through the `.with_options` class method:
76
80
  `:order` - Specifies the order of the dropdown menu, can be ordered by more
77
81
  than one column. e.g.: `"name, email DESC"`.
78
82
 
79
- `:primary_key` - Specifies object's primary_key. Defaults to `:id`.
80
-
81
- `:foreign_key` - Specifies the name of the foreign key directly.
82
- Defaults to `:#{attribute}_id`.
83
-
84
83
  `:scope` - Specifies a custom scope inside a callable. Useful for preloading.
85
84
  Example: `.with_options(scope: -> { MyModel.includes(:rel).limit(5) })`
86
85
 
87
- `:class_name` - Specifies the name of the associated class.
88
- Defaults to `:#{attribute}.to_s.singularize.camelcase`.
86
+ `:include_blank` - Specifies if the select element to be rendered should include
87
+ blank option. Default is `true`.
89
88
 
90
89
  `:searchable` - Specify if the attribute should be considered when searching.
91
90
  Default is `false`.
92
91
 
93
- `searchable_field` - Specify which column to use on the search, only applies
92
+ `searchable_fields` - Specify which columns to use on the search, only applies
94
93
  if `searchable` is `true`
95
94
 
96
95
  For example:
@@ -98,13 +97,19 @@ For example:
98
97
  ```ruby
99
98
  country: Field::BelongsTo.with_options(
100
99
  searchable: true,
101
- searchable_field: 'name',
100
+ searchable_fields: ['name'],
102
101
  )
103
102
  ```
104
103
 
105
104
  with this, you will be able to search through the column `name` from the
106
105
  association `belongs_to :country`, from your model.
107
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
+
108
113
  **Field::HasMany**
109
114
 
110
115
  `:limit` - Set the number of resources to display in the show view. Default is
@@ -114,22 +119,18 @@ association `belongs_to :country`, from your model.
114
119
 
115
120
  `:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.
116
121
 
117
- `:primary_key` - Specifies object's primary_key. Defaults to `:id`.
122
+ `:primary_key` (deprecated) - Specifies object's primary_key.
118
123
 
119
- `:foreign_key` - Specifies the name of the foreign key directly. Defaults to `:#{attribute}_id`
124
+ `:foreign_key` (deprecated) - Specifies the name of the foreign key directly.
120
125
 
121
- `:class_name` - Specifies the name of the associated class.
122
- Defaults to `:#{attribute}.to_s.singularize.camelcase`.
126
+ `:class_name` (deprecated) - Specifies the name of the associated class.
123
127
 
124
128
  **Field::HasOne**
125
129
 
126
- `:class_name` - Specifies the name of the associated class.
127
- Defaults to `:#{attribute}.to_s.singularize.camelcase`.
128
-
129
130
  `:searchable` - Specify if the attribute should be considered when searching.
130
131
  Default is `false`.
131
132
 
132
- `searchable_field` - Specify which column to use on the search, only applies if
133
+ `searchable_fields` - Specify which columns to use on the search, only applies if
133
134
  `searchable` is `true`
134
135
 
135
136
  For example:
@@ -137,13 +138,15 @@ For example:
137
138
  ```ruby
138
139
  cities: Field::HasMany.with_options(
139
140
  searchable: true,
140
- searchable_field: 'name',
141
+ searchable_fields: ['name'],
141
142
  )
142
143
  ```
143
144
 
144
145
  with this, you will be able to search through the column `name` from the
145
146
  association `has_many :cities`, from your model.
146
147
 
148
+ `:class_name` (deprecated) - Specifies the name of the associated class.
149
+
147
150
  **Field::Number**
148
151
 
149
152
  `:searchable` - Specify if the attribute should be considered when searching.
@@ -156,6 +159,13 @@ more results than expected. Default is `false`.
156
159
 
157
160
  `:suffix` - Suffixes the number with a string. Defaults to `""`.
158
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
+
159
169
  For example, you might use the following to display U.S. currency:
160
170
 
161
171
  ```ruby
@@ -163,15 +173,25 @@ For example, you might use the following to display U.S. currency:
163
173
  prefix: "$",
164
174
  decimals: 2,
165
175
  )
176
+
177
+ # "$5.99"
166
178
  ```
167
179
 
168
- Or, to display a distance in kilometers:
180
+ Or, to display a distance in kilometers, using a space as the delimiter:
169
181
 
170
182
  ```ruby
171
- unit_price: Field::Number.with_options(
183
+ distance: Field::Number.with_options(
172
184
  suffix: " km",
173
185
  decimals: 2,
186
+ format: {
187
+ formatter: :number_to_delimited,
188
+ formatter_options: {
189
+ delimiter: ' ',
190
+ },
191
+ },
174
192
  )
193
+
194
+ # "2 000.00 km"
175
195
  ```
176
196
 
177
197
  **Field::Polymorphic**
@@ -190,13 +210,22 @@ objects to display as.
190
210
  `:timezone` - Specify which timezone `Date` and `DateTime` objects are based
191
211
  in.
192
212
 
213
+ **Field::Date**
214
+
215
+ `:format` - Specify what format, using `strftime` you would like `Date`
216
+ objects to display as.
217
+
193
218
  **Field::Select**
194
219
 
195
- `: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 `[]`.
196
222
 
197
223
  `:searchable` - Specify if the attribute should be considered when searching.
198
224
  Default is `true`.
199
225
 
226
+ `:include_blank` - Specifies if the select element to be rendered should include
227
+ blank option. Default is `false`.
228
+
200
229
  **Field::String**
201
230
 
202
231
  `:searchable` - Specify if the attribute should be considered when searching.
@@ -213,6 +242,14 @@ Default is `false`.
213
242
  `:truncate` - Set the number of characters to display in the index view.
214
243
  Defaults to `50`.
215
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
+
216
253
  **Field::Password**
217
254
 
218
255
  `:searchable` - Specify if the attribute should be considered when searching.
@@ -265,19 +302,6 @@ en:
265
302
  other: Happy Customers
266
303
  ```
267
304
 
268
- ## Customizing Actions
269
-
270
- To enable or disable certain actions you could override `valid_action?` method in your dashboard controller like this:
271
-
272
- ```ruby
273
- # disable 'edit' and 'destroy' links
274
- def valid_action?(name, resource = resource_class)
275
- %w[edit destroy].exclude?(name.to_s) && super
276
- end
277
- ```
278
-
279
- Action is one of `new`, `edit`, `show`, `destroy`.
280
-
281
305
  ## Collection Filters
282
306
 
283
307
  Resources can be filtered with pre-set filters. For example if we added:
@@ -305,3 +329,32 @@ COLLECTION_FILTERS = {
305
329
  inactive: ->(resources) { resources.inactive }
306
330
  }
307
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
 
@@ -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