administrate 0.11.0 → 0.17.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/associative.js +5 -0
- data/app/assets/javascripts/administrate/components/date_time_picker.js +6 -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 +4 -3
- data/app/assets/stylesheets/administrate/components/_buttons.scss +11 -0
- data/app/assets/stylesheets/administrate/components/_cells.scss +2 -0
- data/app/assets/stylesheets/administrate/components/_field-unit.scss +17 -4
- data/app/assets/stylesheets/administrate/components/_flashes.scss +0 -8
- data/app/assets/stylesheets/administrate/components/_main-content.scss +1 -0
- 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 +50 -16
- data/app/controllers/concerns/administrate/punditize.rb +3 -3
- data/app/helpers/administrate/application_helper.rb +41 -15
- data/app/views/administrate/application/_collection.html.erb +24 -26
- data/app/views/administrate/application/_collection_header_actions.html.erb +4 -0
- data/app/views/administrate/application/_collection_item_actions.html.erb +17 -0
- data/app/views/administrate/application/_flashes.html.erb +1 -0
- data/app/views/administrate/application/_form.html.erb +3 -3
- data/app/views/administrate/application/{_icons.erb → _icons.html.erb} +1 -1
- data/app/views/administrate/application/_index_header.html.erb +28 -0
- data/app/views/administrate/application/_navigation.html.erb +5 -3
- data/app/views/administrate/application/index.html.erb +9 -29
- data/app/views/administrate/application/show.html.erb +1 -1
- data/app/views/fields/belongs_to/_form.html.erb +3 -3
- 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/has_one/_index.html.erb +1 -1
- data/app/views/fields/has_one/_show.html.erb +4 -4
- data/app/views/fields/number/_form.html.erb +1 -1
- data/app/views/fields/polymorphic/_show.html.erb +1 -1
- data/app/views/fields/select/_form.html.erb +24 -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 +3 -2
- data/app/views/fields/time/_index.html.erb +3 -1
- data/app/views/fields/time/_show.html.erb +3 -1
- 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 +2 -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.fi.yml +30 -0
- data/config/locales/administrate.fr.yml +4 -2
- data/config/locales/administrate.id.yml +2 -0
- data/config/locales/administrate.it.yml +2 -0
- data/config/locales/administrate.ja.yml +2 -0
- data/config/locales/administrate.ko.yml +12 -10
- data/config/locales/administrate.nl.yml +7 -5
- data/config/locales/administrate.pl.yml +2 -0
- data/config/locales/administrate.pt-BR.yml +4 -2
- data/config/locales/administrate.pt.yml +4 -2
- data/config/locales/administrate.ru.yml +2 -0
- data/config/locales/{administrate.al.yml → administrate.sq.yml} +3 -1
- data/config/locales/administrate.sv.yml +2 -0
- data/config/locales/administrate.tr.yml +30 -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 +2 -0
- data/config/unicorn.rb +8 -13
- data/docs/adding_controllers_without_related_model.md +52 -0
- data/docs/adding_custom_field_types.md +3 -1
- data/docs/authentication.md +3 -1
- data/docs/authorization.md +5 -3
- data/docs/customizing_attribute_partials.md +5 -2
- data/docs/customizing_controller_actions.md +50 -2
- data/docs/customizing_dashboards.md +112 -31
- data/docs/customizing_page_views.md +18 -4
- data/docs/extending_administrate.md +27 -0
- data/docs/getting_started.md +49 -56
- data/docs/guides/hiding_dashboards_from_sidebar.md +19 -0
- data/docs/guides.md +5 -0
- data/docs/rails_api.md +45 -0
- data/lib/administrate/base_dashboard.rb +47 -11
- data/lib/administrate/custom_dashboard.rb +15 -0
- data/lib/administrate/engine.rb +8 -1
- data/lib/administrate/field/associative.rb +49 -5
- data/lib/administrate/field/base.rb +35 -9
- data/lib/administrate/field/belongs_to.rb +13 -3
- data/lib/administrate/field/date.rb +20 -0
- data/lib/administrate/field/deferred.rb +22 -3
- data/lib/administrate/field/has_many.rb +16 -3
- data/lib/administrate/field/has_one.rb +32 -12
- data/lib/administrate/field/number.rb +19 -2
- data/lib/administrate/field/polymorphic.rb +5 -5
- data/lib/administrate/field/select.rb +10 -1
- data/lib/administrate/field/time.rb +11 -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 +7 -5
- data/lib/administrate/page/form.rb +10 -3
- data/lib/administrate/resource_resolver.rb +2 -2
- data/lib/administrate/search.rb +116 -28
- data/lib/administrate/version.rb +1 -1
- data/lib/administrate/view_generator.rb +9 -3
- data/lib/administrate.rb +19 -0
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +22 -16
- data/lib/generators/administrate/dashboard/templates/controller.rb.erb +35 -10
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +18 -6
- data/lib/generators/administrate/install/install_generator.rb +37 -1
- data/lib/generators/administrate/install/templates/application_controller.rb.erb +4 -4
- data/lib/generators/administrate/routes/routes_generator.rb +21 -26
- data/lib/generators/administrate/views/layout_generator.rb +1 -0
- data/lib/generators/administrate/views/views_generator.rb +5 -4
- metadata +38 -53
- data/app/assets/javascripts/administrate/components/has_many_form.js +0 -3
- data/config/secrets.yml +0 -14
@@ -22,8 +22,10 @@ pt-BR:
|
|
22
22
|
more: "Exibindo %{count} de %{total_count}"
|
23
23
|
none: Nenhum
|
24
24
|
form:
|
25
|
-
error:
|
26
|
-
errors: "%{pluralized_errors}
|
25
|
+
error: erro
|
26
|
+
errors: "%{pluralized_errors} impediram %{resource_name} de ser gravado:"
|
27
|
+
navigation:
|
28
|
+
back_to_app: Voltar ao aplicativo
|
27
29
|
search:
|
28
30
|
clear: Limpar pesquisa
|
29
31
|
label: Pesquisa %{resource}
|
@@ -22,8 +22,10 @@ pt:
|
|
22
22
|
more: "Mostrando %{count} de %{total_count}"
|
23
23
|
none: Nenhum
|
24
24
|
form:
|
25
|
-
error:
|
26
|
-
errors: "%{pluralized_errors}
|
25
|
+
error: erro
|
26
|
+
errors: "%{pluralized_errors} impediram %{resource_name} de ser gravado:"
|
27
|
+
navigation:
|
28
|
+
back_to_app: Voltar à aplicação
|
27
29
|
search:
|
28
30
|
clear: Limpar pesquisa
|
29
31
|
label: Pesquisa %{resource}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
|
2
|
+
sq:
|
3
3
|
administrate:
|
4
4
|
actions:
|
5
5
|
confirm: A jeni te sigurtë?
|
@@ -23,6 +23,8 @@ al:
|
|
23
23
|
form:
|
24
24
|
error: gabim
|
25
25
|
errors: "%{pluralized_errors} nuk e lejoj %{resource_name} të ruhet:"
|
26
|
+
navigation:
|
27
|
+
back_to_app: Kthehu tek aplikacioni
|
26
28
|
search:
|
27
29
|
clear: Pastro kërkimin
|
28
30
|
label: Kërko %{resource}
|
@@ -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"
|
@@ -21,8 +21,10 @@ zh-CN:
|
|
21
21
|
more: 显示所有 %{total_count} 中 %{count} 条
|
22
22
|
none: 无
|
23
23
|
form:
|
24
|
-
error:
|
25
|
-
errors: "%{
|
24
|
+
error: 错误
|
25
|
+
errors: "%{resource_name} 保存前出现了 %{pluralized_errors} 个错误:"
|
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["
|
4
|
-
timeout
|
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
|
9
|
+
puts "Unicorn master intercepting TERM and sending myself QUIT instead"
|
10
10
|
Process.kill "QUIT", Process.pid
|
11
11
|
end
|
12
12
|
|
13
|
-
|
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
|
19
|
+
puts "Unicorn worker intercepting TERM and doing nothing. " \
|
20
|
+
"Wait for master to send QUIT"
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
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
|
+
```
|
data/docs/authentication.md
CHANGED
data/docs/authorization.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
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
|
-
|
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,48 @@ 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
|
+
```
|
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
|
-
|
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/
|
11
|
+
require "administrate/base_dashboard"
|
10
12
|
|
11
|
-
class CustomerDashboard < Administrate::
|
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
|
-
`:
|
88
|
-
|
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
|
-
`
|
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
|
-
|
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.
|
122
|
+
`:primary_key` (deprecated) - Specifies object's primary_key.
|
118
123
|
|
119
|
-
`:foreign_key` - Specifies the name of the foreign key directly.
|
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
|
-
`
|
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
|
-
|
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
|
-
|
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
|
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,15 +302,59 @@ en:
|
|
265
302
|
other: Happy Customers
|
266
303
|
```
|
267
304
|
|
268
|
-
##
|
305
|
+
## Collection Filters
|
269
306
|
|
270
|
-
|
307
|
+
Resources can be filtered with pre-set filters. For example if we added:
|
271
308
|
|
272
309
|
```ruby
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
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
|
+
]
|
277
358
|
```
|
278
359
|
|
279
|
-
|
360
|
+
Or for custom action with constant name `"FORM_ATTRIBUTES_#{action.upcase}"`
|
@@ -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
|
|