mini-max-mod 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. checksums.yaml +7 -0
  2. data/administrate-1.0.0/Rakefile +30 -0
  3. data/administrate-1.0.0/app/assets/builds/administrate/application.css +2614 -0
  4. data/administrate-1.0.0/app/assets/builds/administrate/application.css.map +1 -0
  5. data/administrate-1.0.0/app/assets/builds/administrate/application.js +31661 -0
  6. data/administrate-1.0.0/app/assets/builds/administrate/application.js.map +7 -0
  7. data/administrate-1.0.0/app/assets/builds/administrate-internal/docs.css +102 -0
  8. data/administrate-1.0.0/app/assets/builds/administrate-internal/docs.css.map +1 -0
  9. data/administrate-1.0.0/app/assets/config/administrate_manifest.js +2 -0
  10. data/administrate-1.0.0/app/assets/javascripts/administrate/add_jquery.js +4 -0
  11. data/administrate-1.0.0/app/assets/javascripts/administrate/application.js +9 -0
  12. data/administrate-1.0.0/app/assets/javascripts/administrate/controllers/application.js +9 -0
  13. data/administrate-1.0.0/app/assets/javascripts/administrate/controllers/index.js +9 -0
  14. data/administrate-1.0.0/app/assets/javascripts/administrate/controllers/select_controller.js +25 -0
  15. data/administrate-1.0.0/app/assets/javascripts/administrate/controllers/table_controller.js +23 -0
  16. data/administrate-1.0.0/app/assets/javascripts/administrate/controllers/tooltip_controller.js +24 -0
  17. data/administrate-1.0.0/app/assets/javascripts/administrate/vendor/css-anchor-positioning.js +9310 -0
  18. data/administrate-1.0.0/app/assets/stylesheets/administrate/application.scss +29 -0
  19. data/administrate-1.0.0/app/assets/stylesheets/administrate/base/_forms.scss +107 -0
  20. data/administrate-1.0.0/app/assets/stylesheets/administrate/base/_layout.scss +25 -0
  21. data/administrate-1.0.0/app/assets/stylesheets/administrate/base/_lists.scss +19 -0
  22. data/administrate-1.0.0/app/assets/stylesheets/administrate/base/_tables.scss +58 -0
  23. data/administrate-1.0.0/app/assets/stylesheets/administrate/base/_typography.scss +59 -0
  24. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_app-container.scss +9 -0
  25. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_attributes.scss +28 -0
  26. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_buttons.scss +88 -0
  27. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_cells.scss +54 -0
  28. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_field-unit.scss +56 -0
  29. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_flashes.scss +20 -0
  30. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_form-actions.scss +3 -0
  31. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_main-content.scss +30 -0
  32. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_navigation.scss +32 -0
  33. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_pagination.scss +18 -0
  34. data/administrate-1.0.0/app/assets/stylesheets/administrate/components/_search.scss +87 -0
  35. data/administrate-1.0.0/app/assets/stylesheets/administrate/library/_clearfix.scss +7 -0
  36. data/administrate-1.0.0/app/assets/stylesheets/administrate/library/_data-label.scss +8 -0
  37. data/administrate-1.0.0/app/assets/stylesheets/administrate/library/_variables.scss +69 -0
  38. data/administrate-1.0.0/app/assets/stylesheets/administrate/reset/_normalize.scss +453 -0
  39. data/administrate-1.0.0/app/assets/stylesheets/administrate-internal/docs.scss +95 -0
  40. data/administrate-1.0.0/app/controllers/administrate/application_controller.rb +279 -0
  41. data/administrate-1.0.0/app/controllers/concerns/administrate/punditize.rb +52 -0
  42. data/administrate-1.0.0/app/helpers/administrate/application_helper.rb +101 -0
  43. data/administrate-1.0.0/app/views/administrate/application/_collection.html.erb +102 -0
  44. data/administrate-1.0.0/app/views/administrate/application/_collection_header_actions.html.erb +4 -0
  45. data/administrate-1.0.0/app/views/administrate/application/_collection_item_actions.html.erb +17 -0
  46. data/administrate-1.0.0/app/views/administrate/application/_flashes.html.erb +21 -0
  47. data/administrate-1.0.0/app/views/administrate/application/_form.html.erb +60 -0
  48. data/administrate-1.0.0/app/views/administrate/application/_icons.html.erb +21 -0
  49. data/administrate-1.0.0/app/views/administrate/application/_index_header.html.erb +51 -0
  50. data/administrate-1.0.0/app/views/administrate/application/_javascript.html.erb +21 -0
  51. data/administrate-1.0.0/app/views/administrate/application/_navigation.html.erb +20 -0
  52. data/administrate-1.0.0/app/views/administrate/application/_pagination.html.erb +1 -0
  53. data/administrate-1.0.0/app/views/administrate/application/_search.html.erb +25 -0
  54. data/administrate-1.0.0/app/views/administrate/application/_stylesheet.html.erb +14 -0
  55. data/administrate-1.0.0/app/views/administrate/application/edit.html.erb +48 -0
  56. data/administrate-1.0.0/app/views/administrate/application/index.html.erb +55 -0
  57. data/administrate-1.0.0/app/views/administrate/application/new.html.erb +49 -0
  58. data/administrate-1.0.0/app/views/administrate/application/show.html.erb +77 -0
  59. data/administrate-1.0.0/app/views/fields/belongs_to/_form.html.erb +27 -0
  60. data/administrate-1.0.0/app/views/fields/belongs_to/_index.html.erb +27 -0
  61. data/administrate-1.0.0/app/views/fields/belongs_to/_show.html.erb +27 -0
  62. data/administrate-1.0.0/app/views/fields/boolean/_form.html.erb +23 -0
  63. data/administrate-1.0.0/app/views/fields/boolean/_index.html.erb +19 -0
  64. data/administrate-1.0.0/app/views/fields/boolean/_show.html.erb +19 -0
  65. data/administrate-1.0.0/app/views/fields/date/_form.html.erb +22 -0
  66. data/administrate-1.0.0/app/views/fields/date/_index.html.erb +21 -0
  67. data/administrate-1.0.0/app/views/fields/date/_show.html.erb +21 -0
  68. data/administrate-1.0.0/app/views/fields/date_time/_form.html.erb +22 -0
  69. data/administrate-1.0.0/app/views/fields/date_time/_index.html.erb +21 -0
  70. data/administrate-1.0.0/app/views/fields/date_time/_show.html.erb +21 -0
  71. data/administrate-1.0.0/app/views/fields/email/_form.html.erb +23 -0
  72. data/administrate-1.0.0/app/views/fields/email/_index.html.erb +18 -0
  73. data/administrate-1.0.0/app/views/fields/email/_show.html.erb +18 -0
  74. data/administrate-1.0.0/app/views/fields/has_many/_form.html.erb +29 -0
  75. data/administrate-1.0.0/app/views/fields/has_many/_index.html.erb +19 -0
  76. data/administrate-1.0.0/app/views/fields/has_many/_show.html.erb +39 -0
  77. data/administrate-1.0.0/app/views/fields/has_one/_form.html.erb +44 -0
  78. data/administrate-1.0.0/app/views/fields/has_one/_index.html.erb +24 -0
  79. data/administrate-1.0.0/app/views/fields/has_one/_show.html.erb +47 -0
  80. data/administrate-1.0.0/app/views/fields/number/_form.html.erb +23 -0
  81. data/administrate-1.0.0/app/views/fields/number/_index.html.erb +19 -0
  82. data/administrate-1.0.0/app/views/fields/number/_show.html.erb +19 -0
  83. data/administrate-1.0.0/app/views/fields/password/_form.html.erb +23 -0
  84. data/administrate-1.0.0/app/views/fields/password/_index.html.erb +18 -0
  85. data/administrate-1.0.0/app/views/fields/password/_show.html.erb +18 -0
  86. data/administrate-1.0.0/app/views/fields/polymorphic/_form.html.erb +29 -0
  87. data/administrate-1.0.0/app/views/fields/polymorphic/_index.html.erb +25 -0
  88. data/administrate-1.0.0/app/views/fields/polymorphic/_show.html.erb +28 -0
  89. data/administrate-1.0.0/app/views/fields/rich_text/_form.html.erb +22 -0
  90. data/administrate-1.0.0/app/views/fields/rich_text/_index.html.erb +18 -0
  91. data/administrate-1.0.0/app/views/fields/rich_text/_show.html.erb +18 -0
  92. data/administrate-1.0.0/app/views/fields/select/_form.html.erb +33 -0
  93. data/administrate-1.0.0/app/views/fields/select/_index.html.erb +16 -0
  94. data/administrate-1.0.0/app/views/fields/select/_show.html.erb +16 -0
  95. data/administrate-1.0.0/app/views/fields/string/_form.html.erb +23 -0
  96. data/administrate-1.0.0/app/views/fields/string/_index.html.erb +18 -0
  97. data/administrate-1.0.0/app/views/fields/string/_show.html.erb +18 -0
  98. data/administrate-1.0.0/app/views/fields/text/_form.html.erb +22 -0
  99. data/administrate-1.0.0/app/views/fields/text/_index.html.erb +18 -0
  100. data/administrate-1.0.0/app/views/fields/text/_show.html.erb +18 -0
  101. data/administrate-1.0.0/app/views/fields/time/_form.html.erb +22 -0
  102. data/administrate-1.0.0/app/views/fields/time/_index.html.erb +19 -0
  103. data/administrate-1.0.0/app/views/fields/time/_show.html.erb +19 -0
  104. data/administrate-1.0.0/app/views/fields/url/_form.html.erb +23 -0
  105. data/administrate-1.0.0/app/views/fields/url/_index.html.erb +20 -0
  106. data/administrate-1.0.0/app/views/fields/url/_show.html.erb +20 -0
  107. data/administrate-1.0.0/app/views/layouts/administrate/application.html.erb +41 -0
  108. data/administrate-1.0.0/config/locales/administrate.ar.yml +30 -0
  109. data/administrate-1.0.0/config/locales/administrate.bs.yml +29 -0
  110. data/administrate-1.0.0/config/locales/administrate.ca.yml +30 -0
  111. data/administrate-1.0.0/config/locales/administrate.da.yml +30 -0
  112. data/administrate-1.0.0/config/locales/administrate.de.yml +30 -0
  113. data/administrate-1.0.0/config/locales/administrate.en.yml +30 -0
  114. data/administrate-1.0.0/config/locales/administrate.es.yml +30 -0
  115. data/administrate-1.0.0/config/locales/administrate.fi.yml +30 -0
  116. data/administrate-1.0.0/config/locales/administrate.fr.yml +30 -0
  117. data/administrate-1.0.0/config/locales/administrate.id.yml +30 -0
  118. data/administrate-1.0.0/config/locales/administrate.it.yml +30 -0
  119. data/administrate-1.0.0/config/locales/administrate.ja.yml +30 -0
  120. data/administrate-1.0.0/config/locales/administrate.ko.yml +30 -0
  121. data/administrate-1.0.0/config/locales/administrate.nl.yml +30 -0
  122. data/administrate-1.0.0/config/locales/administrate.pl.yml +30 -0
  123. data/administrate-1.0.0/config/locales/administrate.pt-BR.yml +31 -0
  124. data/administrate-1.0.0/config/locales/administrate.pt.yml +31 -0
  125. data/administrate-1.0.0/config/locales/administrate.ru.yml +30 -0
  126. data/administrate-1.0.0/config/locales/administrate.sl.yml +30 -0
  127. data/administrate-1.0.0/config/locales/administrate.sq.yml +30 -0
  128. data/administrate-1.0.0/config/locales/administrate.sv.yml +30 -0
  129. data/administrate-1.0.0/config/locales/administrate.tr.yml +30 -0
  130. data/administrate-1.0.0/config/locales/administrate.uk.yml +30 -0
  131. data/administrate-1.0.0/config/locales/administrate.vi.yml +30 -0
  132. data/administrate-1.0.0/config/locales/administrate.zh-CN.yml +30 -0
  133. data/administrate-1.0.0/config/locales/administrate.zh-TW.yml +30 -0
  134. data/administrate-1.0.0/docs/adding_controllers_without_related_model.md +52 -0
  135. data/administrate-1.0.0/docs/adding_custom_field_types.md +81 -0
  136. data/administrate-1.0.0/docs/authentication.md +63 -0
  137. data/administrate-1.0.0/docs/authorization.md +94 -0
  138. data/administrate-1.0.0/docs/customizing_attribute_partials.md +56 -0
  139. data/administrate-1.0.0/docs/customizing_controller_actions.md +109 -0
  140. data/administrate-1.0.0/docs/customizing_dashboards.md +641 -0
  141. data/administrate-1.0.0/docs/customizing_page_views.md +143 -0
  142. data/administrate-1.0.0/docs/extending_administrate.md +27 -0
  143. data/administrate-1.0.0/docs/getting_started.md +150 -0
  144. data/administrate-1.0.0/docs/guides/customising_search.md +149 -0
  145. data/administrate-1.0.0/docs/guides/hiding_dashboards_from_sidebar.md +21 -0
  146. data/administrate-1.0.0/docs/guides/scoping_has_many_relations.md +27 -0
  147. data/administrate-1.0.0/docs/guides/switching_templates_with_view_variants.md +45 -0
  148. data/administrate-1.0.0/docs/guides.md +8 -0
  149. data/administrate-1.0.0/docs/migrating-to-v1.md +34 -0
  150. data/administrate-1.0.0/docs/rails_api.md +45 -0
  151. data/administrate-1.0.0/lib/administrate/base_dashboard.rb +145 -0
  152. data/administrate-1.0.0/lib/administrate/custom_dashboard.rb +15 -0
  153. data/administrate-1.0.0/lib/administrate/engine.rb +52 -0
  154. data/administrate-1.0.0/lib/administrate/field/associative.rb +72 -0
  155. data/administrate-1.0.0/lib/administrate/field/base.rb +119 -0
  156. data/administrate-1.0.0/lib/administrate/field/belongs_to.rb +55 -0
  157. data/administrate-1.0.0/lib/administrate/field/boolean.rb +15 -0
  158. data/administrate-1.0.0/lib/administrate/field/date.rb +24 -0
  159. data/administrate-1.0.0/lib/administrate/field/date_time.rb +31 -0
  160. data/administrate-1.0.0/lib/administrate/field/deferred.rb +59 -0
  161. data/administrate-1.0.0/lib/administrate/field/email.rb +11 -0
  162. data/administrate-1.0.0/lib/administrate/field/has_many.rb +140 -0
  163. data/administrate-1.0.0/lib/administrate/field/has_one.rb +55 -0
  164. data/administrate-1.0.0/lib/administrate/field/number.rb +46 -0
  165. data/administrate-1.0.0/lib/administrate/field/password.rb +29 -0
  166. data/administrate-1.0.0/lib/administrate/field/polymorphic.rb +52 -0
  167. data/administrate-1.0.0/lib/administrate/field/rich_text.rb +21 -0
  168. data/administrate-1.0.0/lib/administrate/field/select.rb +44 -0
  169. data/administrate-1.0.0/lib/administrate/field/string.rb +21 -0
  170. data/administrate-1.0.0/lib/administrate/field/text.rb +21 -0
  171. data/administrate-1.0.0/lib/administrate/field/time.rb +20 -0
  172. data/administrate-1.0.0/lib/administrate/field/url.rb +25 -0
  173. data/administrate-1.0.0/lib/administrate/generator_helpers.rb +13 -0
  174. data/administrate-1.0.0/lib/administrate/namespace/resource.rb +28 -0
  175. data/administrate-1.0.0/lib/administrate/namespace.rb +35 -0
  176. data/administrate-1.0.0/lib/administrate/not_authorized_error.rb +20 -0
  177. data/administrate-1.0.0/lib/administrate/order.rb +150 -0
  178. data/administrate-1.0.0/lib/administrate/page/base.rb +40 -0
  179. data/administrate-1.0.0/lib/administrate/page/collection.rb +38 -0
  180. data/administrate-1.0.0/lib/administrate/page/form.rb +36 -0
  181. data/administrate-1.0.0/lib/administrate/page/show.rb +32 -0
  182. data/administrate-1.0.0/lib/administrate/page.rb +4 -0
  183. data/administrate-1.0.0/lib/administrate/resource_resolver.rb +44 -0
  184. data/administrate-1.0.0/lib/administrate/search.rb +167 -0
  185. data/administrate-1.0.0/lib/administrate/version.rb +3 -0
  186. data/administrate-1.0.0/lib/administrate/view_generator.rb +48 -0
  187. data/administrate-1.0.0/lib/administrate.rb +8 -0
  188. data/administrate-1.0.0/lib/generators/administrate/dashboard/USAGE +9 -0
  189. data/administrate-1.0.0/lib/generators/administrate/dashboard/dashboard_generator.rb +168 -0
  190. data/administrate-1.0.0/lib/generators/administrate/dashboard/templates/controller.rb.erb +46 -0
  191. data/administrate-1.0.0/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +68 -0
  192. data/administrate-1.0.0/lib/generators/administrate/field/field_generator.rb +31 -0
  193. data/administrate-1.0.0/lib/generators/administrate/field/templates/_form.html.erb +6 -0
  194. data/administrate-1.0.0/lib/generators/administrate/field/templates/_index.html.erb +1 -0
  195. data/administrate-1.0.0/lib/generators/administrate/field/templates/_show.html.erb +1 -0
  196. data/administrate-1.0.0/lib/generators/administrate/field/templates/field_object.rb.erb +7 -0
  197. data/administrate-1.0.0/lib/generators/administrate/install/install_generator.rb +91 -0
  198. data/administrate-1.0.0/lib/generators/administrate/install/templates/application_controller.rb.erb +21 -0
  199. data/administrate-1.0.0/lib/generators/administrate/routes/routes_generator.rb +96 -0
  200. data/administrate-1.0.0/lib/generators/administrate/routes/templates/routes.rb.erb +5 -0
  201. data/administrate-1.0.0/lib/generators/administrate/test_record.rb +21 -0
  202. data/administrate-1.0.0/lib/generators/administrate/views/edit_generator.rb +16 -0
  203. data/administrate-1.0.0/lib/generators/administrate/views/field_generator.rb +50 -0
  204. data/administrate-1.0.0/lib/generators/administrate/views/form_generator.rb +15 -0
  205. data/administrate-1.0.0/lib/generators/administrate/views/index_generator.rb +21 -0
  206. data/administrate-1.0.0/lib/generators/administrate/views/layout_generator.rb +24 -0
  207. data/administrate-1.0.0/lib/generators/administrate/views/navigation_generator.rb +15 -0
  208. data/administrate-1.0.0/lib/generators/administrate/views/new_generator.rb +16 -0
  209. data/administrate-1.0.0/lib/generators/administrate/views/show_generator.rb +15 -0
  210. data/administrate-1.0.0/lib/generators/administrate/views/views_generator.rb +15 -0
  211. data/administrate-1.0.0/lib/tasks/administrate_tasks.rake +4 -0
  212. data/mini-max-mod.gemspec +12 -0
  213. metadata +252 -0
@@ -0,0 +1,641 @@
1
+ ---
2
+ title: Customizing Dashboards
3
+ ---
4
+
5
+ In order to customize which attributes get displayed for each resource,
6
+ edit the dashboard file generated by the installation generator.
7
+
8
+ By default, the file will look something like this:
9
+
10
+ ```ruby
11
+ require "administrate/base_dashboard"
12
+
13
+ class CustomerDashboard < Administrate::BaseDashboard
14
+ ATTRIBUTE_TYPES = {
15
+ id: Field::Number,
16
+ name: Field::String,
17
+ email: Field::String,
18
+ created_at: Field::DateTime,
19
+ updated_at: Field::DateTime,
20
+ orders: Field::HasMany,
21
+ }
22
+
23
+ COLLECTION_ATTRIBUTES = [
24
+ :id,
25
+ :name,
26
+ :email,
27
+ :created_at,
28
+ :updated_at,
29
+ :orders,
30
+ ]
31
+
32
+ SHOW_PAGE_ATTRIBUTES = [
33
+ :id,
34
+ :name,
35
+ :email,
36
+ :created_at,
37
+ :updated_at,
38
+ :orders,
39
+ ]
40
+
41
+ FORM_ATTRIBUTES = [
42
+ :name,
43
+ :email,
44
+ :orders,
45
+ ]
46
+ end
47
+ ```
48
+
49
+ To change which attributes appear on each of the `index`, `show`, and `edit`
50
+ pages, add or remove attributes to each constant array.
51
+
52
+ Finally, the `ATTRIBUTE_TYPES` method defines how each attribute is displayed
53
+ throughout the dashboard. There are a number of `Field` classes that you can
54
+ specify, including:
55
+
56
+ - `Field::BelongsTo`
57
+ - `Field::Boolean`
58
+ - `Field::DateTime`
59
+ - `Field::Date`
60
+ - `Field::Email`
61
+ - `Field::HasMany`
62
+ - `Field::HasOne`
63
+ - `Field::Number`
64
+ - `Field::Polymorphic`
65
+ - `Field::Select`
66
+ - `Field::String`
67
+ - `Field::Text`
68
+ - `Field::Url`
69
+ - `Field::Password`
70
+
71
+ ## Customizing Fields
72
+
73
+ ### Setting Options
74
+
75
+ Each of the `Field` types take a different set of options,
76
+ which are specified through the `.with_options` class method:
77
+
78
+ **Field::BelongsTo**
79
+
80
+ `:order` - Specifies the column used to order the records. It will apply both in
81
+ the table views and in the dropdown menu on the record forms.
82
+ You can set multiple columns as well with direction. E.g.: `"name, email DESC"`.
83
+
84
+ `:scope` - Specifies a custom scope inside a callable. Useful for preloading.
85
+ Example #1: `.with_options(scope: -> { MyModel.includes(:rel).limit(5) })`
86
+ Example #2: `.with_options(scope: -> (field) { field.resource.my_models.includes(:rel).limit(5) })`
87
+
88
+ `:include_blank` - Specifies if the select element to be rendered should include
89
+ blank option. Default is `true`.
90
+
91
+ `:searchable` - Specify if the attribute should be considered when searching.
92
+ Default is `false`.
93
+
94
+ `searchable_fields` - Specify which columns to use on the search, only applies
95
+ if `searchable` is `true`
96
+
97
+ For example:
98
+
99
+ ```ruby
100
+ country: Field::BelongsTo.with_options(
101
+ searchable: true,
102
+ searchable_fields: ['name'],
103
+ )
104
+ ```
105
+
106
+ with this, you will be able to search through the column `name` from the
107
+ association `belongs_to :country`, from your model.
108
+
109
+ `:sortable` - Specifies if sorting should be enabled in the table views.
110
+ Default is `true`.
111
+
112
+ `:sorting_column` - Specifies the column of the associated model to be used for sorting in the table views and dropdown menu.
113
+ If `sorting_column` is omitted and `order` is specified, the value of `order` will be used.
114
+ If neither is specified, sorting will be done using the foreign key.
115
+
116
+ `:class_name` - Specifies the name of the associated class.
117
+
118
+ **Field::HasMany**
119
+
120
+ `:collection_attributes` - Set the columns to display in the show view.
121
+ Default is COLLECTION_ATTRIBUTES in dashboard.
122
+
123
+ `:limit` - The number of resources (paginated) to display in the show view. To disable pagination,
124
+ set this to `0` or `false`. Default is `5`.
125
+
126
+ `:sort_by` - What to sort the association by in the show view.
127
+
128
+ `:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.
129
+
130
+ `:sortable` - Specifies if sorting should be enabled in the table views.
131
+ Default is `true`.
132
+
133
+ `:sorting_column` - Specifies the column of the associated model to be used for sorting in the dropdown menu.
134
+ If `sorting_column` is omitted and `sort_by` is specified, the value of `sort_by` will be used.
135
+ If neither is specified, sorting will be done using the foreign key.
136
+ For `HasMany` associations, sorting is based on the count, so this option is not referenced in the table views.
137
+
138
+ `:class_name` - Specifies the name of the associated class.
139
+
140
+ **Field::HasOne**
141
+
142
+ `:order` - Specifies the column used to order the records. It will apply both in
143
+ the table views and in the dropdown menu on the record forms.
144
+ You can set multiple columns as well with direction. E.g.: `"name, email DESC"`.
145
+
146
+ `:searchable` - Specify if the attribute should be considered when searching.
147
+ Default is `false`.
148
+
149
+ `searchable_fields` - Specify which columns to use on the search, only applies if
150
+ `searchable` is `true`
151
+
152
+ For example:
153
+
154
+ ```ruby
155
+ city: Field::HasOne.with_options(
156
+ searchable: true,
157
+ searchable_fields: ['name'],
158
+ )
159
+ ```
160
+
161
+ with this, you will be able to search through the column `name` from the
162
+ association `has_one :city`, from your model.
163
+
164
+ `:sortable` - Specifies if sorting should be enabled in the table views.
165
+ Default is `true`.
166
+
167
+ `:sorting_column` - Specifies the column of the associated model to be used for sorting in the table views and dropdown menu.
168
+ If `sorting_column` is omitted and `order` is specified, the value of `order` will be used.
169
+ If neither is specified, sorting will be done using the foreign key.
170
+
171
+ `:class_name` - Specifies the name of the associated class.
172
+
173
+ **Field::Number**
174
+
175
+ `:searchable` - Specify if the attribute should be considered when searching.
176
+ Note that currently number fields are searched like text, which may yield
177
+ more results than expected. Default is `false`.
178
+
179
+ `:sortable` - Specifies if sorting should be enabled in the table views.
180
+ Default is `true`.
181
+
182
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
183
+ By default, the column itself is used, but when used as a virtual column,
184
+ a custom sorting column can be specified.
185
+
186
+ `:decimals` - Set the number of decimals to display. Defaults to `0`.
187
+
188
+ `:prefix` - Prefixes the number with a string. Defaults to `""`.
189
+
190
+ `:suffix` - Suffixes the number with a string. Defaults to `""`.
191
+
192
+ `:format` - Specify a hash which defines a formatter. This uses ActiveSupport
193
+ and works by by passing a hash that includes the formatter (`formatter`) and
194
+ the options for the formatter (`formatter_options`). Defaults to the locale's
195
+ delimiter when `formatter_options` does not include a `delimiter`. See the
196
+ example below. All helpers from `ActiveSupport::NumberHelper` are supported.
197
+
198
+ For example, you might use the following to display U.S. currency:
199
+
200
+ ```ruby
201
+ unit_price: Field::Number.with_options(
202
+ prefix: "$",
203
+ decimals: 2,
204
+ )
205
+
206
+ # "$5.99"
207
+ ```
208
+
209
+ Or, to display a distance in kilometers, using a space as the delimiter:
210
+
211
+ ```ruby
212
+ distance: Field::Number.with_options(
213
+ suffix: " km",
214
+ decimals: 2,
215
+ format: {
216
+ formatter: :number_to_delimited,
217
+ formatter_options: {
218
+ delimiter: ' ',
219
+ },
220
+ },
221
+ )
222
+
223
+ # "2 000.00 km"
224
+ ```
225
+
226
+ **Field::Polymorphic**
227
+
228
+ `:classes` - Specify a list of classes whose objects will be used to populate select boxes for editing this polymorphic field.
229
+ Default is `[]`.
230
+
231
+ `:order` - What to sort the association by in the form select.
232
+ Default is `nil`.
233
+
234
+ `:sortable` - Specifies if sorting should be enabled in the table views.
235
+ Default is `true`.
236
+
237
+ **Field::DateTime**
238
+
239
+ `:sortable` - Specifies if sorting should be enabled in the table views.
240
+ Default is `true`.
241
+
242
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
243
+ By default, the column itself is used, but when used as a virtual column,
244
+ a custom sorting column can be specified.
245
+
246
+ `:format` - Specify what format, using `strftime` you would like `DateTime`
247
+ objects to display as.
248
+
249
+ `:timezone` - Specify which timezone `Date` and `DateTime` objects are based
250
+ in.
251
+
252
+ **Field::Date**
253
+
254
+ `:sortable` - Specifies if sorting should be enabled in the table views.
255
+ Default is `true`.
256
+
257
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
258
+ By default, the column itself is used, but when used as a virtual column,
259
+ a custom sorting column can be specified.
260
+
261
+ `:format` - Specify what format, using `strftime` you would like `Date`
262
+ objects to display as.
263
+
264
+ **Field::Select**
265
+
266
+ `:collection` - The options available to select. The format is the same as for Rails's own [`options_for_select`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-options_for_select).
267
+
268
+ If the given value responds to `call`, this will be called and the result used instead. The call will receive an instance of the field as argument. For example:
269
+
270
+ ```ruby
271
+ confirmation: Field::Select.with_options(
272
+ collection: ->(field) {
273
+ person = field.resource
274
+ {
275
+ "no, #{person.name}" => "opt0",
276
+ "yes, #{person.name}" => "opt1",
277
+ "absolutely, #{person.name}" => "opt2",
278
+ }
279
+ },
280
+ )
281
+ ```
282
+
283
+ Administrate will detect if the attribute is an `ActiveRecord::Enum` and extract the available options. Note that if a `collection` is provided it will take precedence.
284
+
285
+ If no collection is provided and no enum can be detected, the list of options will be empty.
286
+
287
+ `:searchable` - Specify if the attribute should be considered when searching.
288
+ Default is `true`.
289
+
290
+ `:sortable` - Specifies if sorting should be enabled in the table views.
291
+ Default is `true`.
292
+
293
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
294
+ By default, the column itself is used, but when used as a virtual column,
295
+ a custom sorting column can be specified.
296
+
297
+ `:include_blank` - Similar to [the option of the same name accepted by Rails helpers](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html). If provided, a "blank" option will be added first to the list of options, with the value of `include_blank` as label.
298
+
299
+ **Field::String**
300
+
301
+ `:searchable` - Specify if the attribute should be considered when searching.
302
+ Default is `true`.
303
+
304
+ `:sortable` - Specifies if sorting should be enabled in the table views.
305
+ Default is `true`.
306
+
307
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
308
+ By default, the column itself is used, but when used as a virtual column,
309
+ a custom sorting column can be specified.
310
+
311
+ `:truncate` - Set the number of characters to display in the index view.
312
+ Defaults to `50`.
313
+
314
+ **Field::Text**
315
+
316
+ `:searchable` - Specify if the attribute should be considered when searching.
317
+ Default is `false`.
318
+
319
+ `:sortable` - Specifies if sorting should be enabled in the table views.
320
+ Default is `true`.
321
+
322
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
323
+ By default, the column itself is used, but when used as a virtual column,
324
+ a custom sorting column can be specified.
325
+
326
+ `:truncate` - Set the number of characters to display in the index view.
327
+ Defaults to `50`.
328
+
329
+ `:input_options` - Options to customize the text area in form view.
330
+ Example: `.with_options(input_options: { rows: 20 })`
331
+
332
+ **Field::Url**
333
+
334
+ `:searchable` - Specify if the attribute should be considered when searching.
335
+ Default is `true`.
336
+
337
+ `:sortable` - Specifies if sorting should be enabled in the table views.
338
+ Default is `true`.
339
+
340
+ `:sorting_column` - Specifies the column to be used for sorting in the table view.
341
+ By default, the column itself is used, but when used as a virtual column,
342
+ a custom sorting column can be specified.
343
+
344
+ `:truncate` - Set the number of characters to display in the index view.
345
+ Defaults to `50`.
346
+
347
+ `:html_options` - Specify anchor tag attributes (e.g., `target="_blank"`).
348
+ Defaults is `{}`.
349
+
350
+ **Field::Password**
351
+
352
+ `:searchable` - Specify if the attribute should be considered when searching.
353
+ Default is `false`.
354
+
355
+ `:sortable` - Specifies if sorting should be enabled in the table views.
356
+ Default is `false`.
357
+
358
+ `:truncate` - Set the number of characters to display in the views.
359
+ Defaults to `50`.
360
+
361
+ `:character` - Set the replace character.
362
+ Defaults to `•`.
363
+
364
+ ### Defining Labels
365
+
366
+ To change the user-facing label for an attribute,
367
+ define a custom I18n translation:
368
+
369
+ ```yaml
370
+ en:
371
+ helpers:
372
+ label:
373
+ customer:
374
+ name: Full Name
375
+ ```
376
+
377
+
378
+ To change the labels used for resources in dashboard collections.
379
+ Assume you have a users dashboard and you want to change "User #1" to "Testy
380
+ McTesterson", the user's name.
381
+
382
+ Add this method to the dashboard for Users.
383
+ Use whatever attribute or method you like.
384
+ Example for *user*:
385
+
386
+ ```ruby
387
+ def display_resource(user)
388
+ user.name
389
+ end
390
+ ```
391
+
392
+ [define your own]: /adding_custom_field_types
393
+
394
+ To change the dashboard name in sidebar menu, sub-header and search string use default ActiveRecord i18n translations for models:
395
+
396
+ ```yaml
397
+ en:
398
+ activerecord:
399
+ models:
400
+ customer:
401
+ one: Happy Customer
402
+ other: Happy Customers
403
+ ```
404
+
405
+ ## Collection Filters
406
+
407
+ Resources can be filtered with pre-set filters. For example if we added:
408
+
409
+ ```ruby
410
+ COLLECTION_FILTERS = {
411
+ inactive: ->(resources) { resources.where("login_at < ?", 1.week.ago) }
412
+ }
413
+ ```
414
+
415
+ …to a dashboard, we can query the resources of that dashboard with:
416
+
417
+ ```ruby
418
+ bob inactive:
419
+ ```
420
+
421
+ …to find users named "bob" who hasn't logged in the last week.
422
+
423
+ If you already had the `inactive` scope you could define the filter like so to
424
+ take advantage of existing ActiveRecord scopes (and other class methods on the
425
+ resource class).
426
+
427
+ ```ruby
428
+ COLLECTION_FILTERS = {
429
+ inactive: ->(resources) { resources.inactive }
430
+ }
431
+ ```
432
+
433
+ You can also define a filter with parameters:
434
+
435
+ ```ruby
436
+ COLLECTION_FILTERS = {
437
+ state: ->(resources, attr) { resources.where(state: attr) }
438
+ }
439
+ ```
440
+
441
+ You can now search your resource with 'state:open' and your
442
+ collection filter Proc will be called with with attr = open.
443
+
444
+ ## Form Attributes
445
+
446
+ You can define different attributes for new/create or edit/update actions:
447
+
448
+ ```ruby
449
+ FORM_ATTRIBUTES_NEW = [
450
+ :name,
451
+ :email
452
+ ]
453
+ FORM_ATTRIBUTES_EDIT = [
454
+ :name,
455
+ :email,
456
+ :orders
457
+ ]
458
+ ```
459
+
460
+ Or for custom action with constant name `"FORM_ATTRIBUTES_#{action.upcase}"`
461
+
462
+ ### Form Fields' Hints
463
+
464
+ You can show a brief text element below an input field by setting the
465
+ corresponding translation key using the path:
466
+
467
+ `administrate.field_hints.#{model_name}.#{field_name}`
468
+
469
+ For example, with a Customer dashboard with an email field you can add a
470
+ string value that will be used as text hint:
471
+
472
+ ```yml
473
+ en:
474
+ administrate:
475
+ field_hints:
476
+ customer:
477
+ email: field_hint
478
+ ```
479
+
480
+ ## Grouped Attributes
481
+
482
+ You may have models with a large number of fields and therefore you might want to group them in a meaningul way:
483
+
484
+ ```ruby
485
+ class UserDashboard < Administrate::BaseDashboard
486
+ SHOW_PAGE_ATTRIBUTES = {
487
+ "" => [:username],
488
+ "Personal Information" => [:first_name, :last_name, :email],
489
+ "Address" => [:address_line_one, :address_line_two, :address_city, :address_state, :address_country]
490
+ }
491
+
492
+ FORM_ATTRIBUTES = {
493
+ "" => [:username, :password, :password_confirmation],
494
+ "personal_information" => [:first_name, :last_name, :email],
495
+ "address" => [:address_line_one, :address_line_two, :address_city, :address_state, :address_country]
496
+ }
497
+ end
498
+ ```
499
+
500
+ You can optionally translate your group labels:
501
+
502
+ ```yaml
503
+ en:
504
+ helpers:
505
+ label:
506
+ user:
507
+ address: Address
508
+ personal_information: Personal Information
509
+ ```
510
+
511
+ If not defined (see `SHOW_PAGE_ATTRIBUTES` above), Administrate will default to the given strings.
512
+
513
+ ## Virtual Attributes
514
+
515
+ For all field types, you can use the `getter` option to change where the data is retrieved from or to set the data directly.
516
+
517
+ By using this, you can define an attribute in `ATTRIBUTE_TYPES` that doesn’t exist in the model, and use it for various purposes.
518
+
519
+ ### Attribute Aliases
520
+
521
+ You can create an alias for an attribute. For example:
522
+
523
+ ```ruby
524
+ ATTRIBUTE_TYPES = {
525
+ shipped_at: Field::DateTime,
526
+ shipped_on: Field::Date.with_options(
527
+ getter: :shipped_at
528
+ )
529
+ }
530
+ COLLECTION_ATTRIBUTES = [
531
+ :shipped_on
532
+ }
533
+ SHOW_PAGE_ATTRIBUTES = [
534
+ :shipped_at
535
+ }
536
+ ```
537
+
538
+ In this example, a virtual attribute `shipped_on` based on the value of `shipped_at` is defined as a `Date` type and used for display on the index page (this can help save table cell space).
539
+
540
+ ### Decorated Attributes
541
+
542
+ You can also use this to decorate data. For example:
543
+
544
+ ```ruby
545
+ ATTRIBUTE_TYPES = {
546
+ price: Field::Number,
547
+ price_including_tax: Field::Number.with_options(
548
+ getter: -> (field) {
549
+ field.resource.price * 1.1 if field.resource.price.present?
550
+ }
551
+ )
552
+ }
553
+ ```
554
+
555
+ ### Composite Attributes
556
+
557
+ You can dynamically create a virtual attribute by combining multiple attributes for display. For example:
558
+
559
+ ```ruby
560
+ ATTRIBUTE_TYPES = {
561
+ first_name: Field::String,
562
+ last_name: Field::String,
563
+ full_name: Field::String.with_options(
564
+ getter: -> (field) {
565
+ [
566
+ field.resource.first_name,
567
+ field.resource.last_name
568
+ ].compact_blank.join(' ')
569
+ }
570
+ )
571
+ }
572
+ ```
573
+
574
+ ## Virtual Fields
575
+
576
+ Custom fields can also be defined using virtual fields.
577
+
578
+ ```ruby
579
+ ATTRIBUTE_TYPES = {
580
+ id: Field::Number,
581
+ receipt: Field::ReceiptLink
582
+ }
583
+ ```
584
+
585
+ ```ruby
586
+ module Administrate
587
+ module Field
588
+ class ReceiptLink < Base
589
+ def data
590
+ resource.id
591
+ end
592
+
593
+ def filename
594
+ "receipt-#{data}.pdf"
595
+ end
596
+
597
+ def url
598
+ "/files/receipts/#{filename}"
599
+ end
600
+ end
601
+ end
602
+ end
603
+ ```
604
+
605
+ ```erb
606
+ <%= link_to field.filename, field.url %>
607
+ ```
608
+
609
+ ### Custom Actions via Virtual Field
610
+
611
+ By creating custom fields that are not dependent on specific attributes, you can insert custom views into any screen.
612
+ For example, you can add custom buttons like this:
613
+
614
+ ```ruby
615
+ ATTRIBUTE_TYPES = {
616
+ id: Field::Number,
617
+ custom_index_actions: Field::CustomActionButtons,
618
+ custom_show_actions: Field::CustomActionButtons,
619
+ }
620
+ ```
621
+
622
+ ```ruby
623
+ module Administrate
624
+ module Field
625
+ class CustomActionButtons < Base
626
+ def data
627
+ resource.id
628
+ end
629
+ end
630
+ end
631
+ end
632
+ ```
633
+
634
+ ```erb
635
+ <%# app/views/fields/custom_action_buttons/_index.html.erb %>
636
+ <% if field.data.present? %>
637
+ <%= button_to "some action 1", [:some_action_1, namespace, field.resource] %>
638
+ <%= button_to "some action 2", [:some_action_2, namespace, field.resource] %>
639
+ <%= button_to "some action 3", [:some_action_3, namespace, field.resource] %>
640
+ <% end %>
641
+ ```