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,143 @@
1
+ ---
2
+ title: Customizing page views
3
+ ---
4
+
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/admin/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
20
+
21
+ ## Customizing for all resources
22
+
23
+ In order to change the appearance of views for all resource types,
24
+ call the generators with no arguments.
25
+
26
+ ```bash
27
+ rails generate administrate:views:index
28
+ # -> app/views/admin/application/index.html.erb
29
+ # -> app/views/admin/application/_collection.html.erb
30
+
31
+ rails generate administrate:views:show
32
+ # -> app/views/admin/application/show.html.erb
33
+
34
+ rails generate administrate:views:edit
35
+ # -> app/views/admin/application/edit.html.erb
36
+ # -> app/views/admin/application/_form.html.erb
37
+
38
+ rails generate administrate:views:new
39
+ # -> app/views/admin/application/new.html.erb
40
+ # -> app/views/admin/application/_form.html.erb
41
+
42
+ rails generate administrate:views
43
+ # -> all of the above
44
+ ```
45
+
46
+ The generators copy over the default views that Administrate uses,
47
+ so you have a good starting point for customizations.
48
+ Feel free to change up the file type,
49
+ add extra sections to the page,
50
+ or blow it all away for your own custom look.
51
+
52
+ ## Customizing for a specific resource
53
+
54
+ In order to change a dashboard page for a single type of resource,
55
+ pass in the resource name to the view generators.
56
+
57
+ ```bash
58
+ rails generate administrate:views:index User
59
+ # -> app/views/admin/users/index.html.erb
60
+ # -> app/views/admin/users/_collection.html.erb
61
+
62
+ rails generate administrate:views:show User
63
+ # -> app/views/admin/users/show.html.erb
64
+
65
+ rails generate administrate:views:edit User
66
+ # -> app/views/admin/users/edit.html.erb
67
+ # -> app/views/admin/users/_form.html.erb
68
+
69
+ rails generate administrate:views:new User
70
+ # -> app/views/admin/users/new.html.erb
71
+ # -> app/views/admin/users/_form.html.erb
72
+
73
+ rails generate administrate:views User
74
+ # -> all of the above
75
+ ```
76
+
77
+ Any changes to these template files
78
+ will *only* affect pages that display customers,
79
+ and will leave the show pages for other resources unchanged.
80
+
81
+ ## Customizing layouts
82
+
83
+ Many developers need to customize the layouts of their admin dashboard.
84
+ It's as easy as passing in the "layout" keyword to the view generators.
85
+
86
+ ```bash
87
+ rails generate administrate:views:layout
88
+ # -> app/views/layouts/admin/application.html.erb
89
+ # -> app/views/admin/application/_navigation.html.erb
90
+ # -> app/views/admin/application/_javascript.html.erb
91
+ # -> app/views/admin/application/_flashes.html.erb
92
+
93
+ rails generate administrate:views:navigation
94
+ # It only generates the sidebar partial
95
+ # -> app/views/admin/application/_navigation.html.erb
96
+ ```
97
+
98
+ ## Customizing for a specific layout
99
+
100
+ You can use several hook points to add elements to specific layouts or specific pages:
101
+
102
+ * header_middle
103
+ * header_last
104
+ * before_main
105
+ * main
106
+ * after_main
107
+
108
+ For example, you can add a button in the middle of the header as follows:
109
+
110
+ ```eruby
111
+ <%# app/views/admin/customers/_index_header.html.erb %>
112
+
113
+ <% content_for(:header_middle) do %>
114
+ <div>
115
+ You are logged in as <em><%= pundit_user.name %></em>.
116
+ <%= link_to("Become the Admin", become_admin_customer_path("admin")) unless pundit_user.admin? %>
117
+ </div>
118
+ <% end %>
119
+
120
+ <%= render template: 'administrate/application/_index_header', locals: local_assigns %>
121
+ ```
122
+
123
+ ## Adding custom CSS and JS
124
+
125
+ You can add custom CSS and JS to Administrate. Put the files in the
126
+ appropriate folders (typically under `assets`) and point Administrate to them
127
+ using the following API, preferably in an initializer. For example, if your
128
+ files are called `admin.css` and `admin.js`:
129
+
130
+ ```
131
+ /// config/initializers/administrate.rb
132
+ Administrate::Engine.add_stylesheet("admin")
133
+ Administrate::Engine.add_javascript("admin")
134
+ ```
135
+
136
+ Then make sure to list them in your manifest file (Rails will helpfully remind
137
+ you of this step if you miss it):
138
+
139
+ ```
140
+ /// app/assets/config/manifest.js
141
+ //= link admin.css
142
+ //= link admin.js
143
+ ```
@@ -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
@@ -0,0 +1,150 @@
1
+ ---
2
+ title: Getting Started
3
+ ---
4
+
5
+ Administrate is released as a Ruby gem, and can be installed on Rails
6
+ applications version 6.0 or greater. We support Ruby 3.0 and up.
7
+
8
+ First, add the following to your Gemfile:
9
+
10
+ ```ruby
11
+ # Gemfile
12
+ gem "administrate"
13
+ ```
14
+
15
+ Re-bundle with `bundle install`, then run the installer:
16
+
17
+ ```bash
18
+ $ rails generate administrate:install
19
+ ```
20
+
21
+ The installer adds some new routes to your `config/routes.rb`,
22
+ and creates a controller at `app/controllers/admin/application_controller.rb`
23
+
24
+ In addition, the generator creates a `Dashboard` and a `Controller` for each of
25
+ your ActiveRecord resources:
26
+
27
+ - `app/controllers/admin/foos_controller.rb`
28
+ - `app/dashboards/foo_dashboard.rb`
29
+
30
+ The `Admin::ApplicationController` can be customized to add
31
+ authentication logic, authorization, pagination,
32
+ or other controller-level concerns.
33
+
34
+ You will also want to add a `root` route to show a dashboard when you go to `/admin`.
35
+
36
+ ```ruby
37
+ Rails.application.routes.draw do
38
+ namespace :admin do
39
+ # Add dashboard for your models here
40
+ resources :customers
41
+ resources :orders
42
+
43
+ root to: "customers#index" # <--- Root route
44
+ end
45
+ end
46
+ ```
47
+
48
+ The routes can be customized to show or hide
49
+ different models on the dashboard.
50
+
51
+ Each `FooDashboard` specifies which attributes should be displayed
52
+ on the admin dashboard for the `Foo` resource.
53
+
54
+ Each `Admin::FooController` can be overwritten to specify custom behavior.
55
+
56
+ Once you have Administrate installed,
57
+ visit <http://localhost:3000/admin> to see your new dashboard in action.
58
+
59
+ ### Errors about assets?
60
+
61
+ If your apps uses Sprockets 4, you'll need to add Administrate's assets to
62
+ your `manifest.js` file. To do this, add these two lines to the file:
63
+
64
+ ```
65
+ //= link administrate/application.css
66
+ //= link administrate/application.js
67
+ ```
68
+
69
+ Otherwise, your app will show you this error:
70
+
71
+ ```
72
+ Asset `administrate/application.css` was not declared to be precompiled in production.
73
+ Declare links to your assets in `app/assets/config/manifest.js`.
74
+ ```
75
+
76
+ For more information on why this is necessary, see Richard Schneeman's article
77
+ ["Self Hosted Config: Introducing the Sprockets manifest.js"][]
78
+
79
+ [schneems]: https://www.schneems.com/2017/11/22/self-hosted-config-introducing-the-sprockets-manifestjs
80
+
81
+ ## Create Additional Dashboards
82
+
83
+ In order to create additional dashboards, pass in the resource name to
84
+ the dashboard generator. A dashboard and controller will be created.
85
+
86
+ ```bash
87
+ $ rails generate administrate:dashboard Foo
88
+ ```
89
+
90
+ Then add a route for the new dashboard.
91
+
92
+ ```ruby
93
+ # config/routes.rb
94
+
95
+ namespace :admin do
96
+ resources :foos
97
+ end
98
+ ```
99
+
100
+ ## Using a Custom Namespace
101
+
102
+ Administrate supports using a namespace other than `Admin`, such as
103
+ `Supervisor`. This will also change the route it's using:
104
+
105
+ ```sh
106
+ rails generate administrate:install --namespace=supervisor
107
+ ```
108
+
109
+ ## Keep Dashboards Updated as Model Attributes Change
110
+
111
+ If you've installed Administrate and generated dashboards and _then_
112
+ subsequently added attributes to your models you'll need to manually add
113
+ these additions (or removals) to your dashboards.
114
+
115
+ Example:
116
+
117
+ ```ruby
118
+ # app/dashboards/your_model_dashboard.rb
119
+
120
+ ATTRIBUTE_TYPES = {
121
+ # ...
122
+ the_new_attribute: Field::String,
123
+ # ...
124
+ }.freeze
125
+
126
+ SHOW_PAGE_ATTRIBUTES = [
127
+ # ...
128
+ :the_new_attribute,
129
+ # ...
130
+ ].freeze
131
+
132
+ FORM_ATTRIBUTES = [
133
+ # ...
134
+ :the_new_attribute,
135
+ # ...
136
+ ].freeze
137
+
138
+ COLLECTION_ATTRIBUTES = [
139
+ # ...
140
+ :the_new_attribute, # if you want it on the index, also.
141
+ # ...
142
+ ].freeze
143
+ ```
144
+
145
+ It's recommended that you make this change at the same time as you add the
146
+ attribute to the model.
147
+
148
+ The alternative way to handle this is to re-run `rails g administrate:install`
149
+ and carefully pick through the diffs. This latter method is probably more
150
+ cumbersome.
@@ -0,0 +1,149 @@
1
+ ---
2
+ title: Customising the search
3
+ ---
4
+
5
+ Administrate dashboards provide a search function, but it is quite basic.
6
+ Things like search across complex associations, inside JSON columns, or outside
7
+ the database (eg: an Elasticsearch index) are not possible out of the box.
8
+
9
+ Fortunately, Administrate is just Rails, so you can use your existing Rails
10
+ knowledge to customize the search feature. Let's look into that.
11
+
12
+ ## In short
13
+
14
+ Override the `filter_resources` method in your admin controllers in order
15
+ to customize the search.
16
+
17
+ It has two parameters:
18
+
19
+ * `resources`: an ActiveRecord relation for the model on whose dashboard the
20
+ search originated.
21
+ * `search_term:`: a string representing the search query entered by the user.
22
+
23
+ Return an ActiveRecord relation for the same model as `resources`, matching
24
+ the desired search results.
25
+
26
+ ## In more detail
27
+
28
+ When you install Administrate in your application, it generates an admin
29
+ controller for each of your ActiveRecord models, as well as a base controller
30
+ that all of these inherit from.
31
+
32
+ For example, if you have two ActiveRecord models: `Person` and `Address`,
33
+ running `rails generate administrate:install` will get you the following
34
+ files (plus others that are not relevant here):
35
+
36
+ * `app/controllers/admin/people_controller.rb`
37
+ * `app/controllers/admin/addresses_controller.rb`
38
+ * `app/controllers/admin/application_controller.rb`
39
+
40
+ By default, searches are handled by the `index` action of the controller that
41
+ the user was visiting when they performed the search. For example, if a user
42
+ is visiting the People dashboard and submits a search, the user is sent to
43
+ the path `/admin/people?search=<search query>`. This is routed to
44
+ `Admin::PeopleController#index`, where the search query can be read as
45
+ `params[:search]`.
46
+
47
+ By default, these controllers are empty. Administrate's code is implemented
48
+ at `Administrate::ApplicationController`, from which all inherit. This is
49
+ where search is implemented. You can read the code yourself at:
50
+ https://github.com/thoughtbot/administrate/blob/main/app/controllers/administrate/application_controller.rb.
51
+
52
+ It is in the linked code that you can see what Administrate actually does.
53
+ For example, this is the `index` action at the time of writing these lines:
54
+
55
+ ```ruby
56
+ def index
57
+ authorize_resource(resource_class)
58
+ search_term = params[:search].to_s.strip
59
+ resources = filter_resources(scoped_resource, search_term: search_term)
60
+ resources = apply_collection_includes(resources)
61
+ resources = order.apply(resources)
62
+ resources = resources.page(params[:_page]).per(records_per_page)
63
+ page = Administrate::Page::Collection.new(dashboard, order: order)
64
+
65
+ render locals: {
66
+ resources: resources,
67
+ search_term: search_term,
68
+ page: page,
69
+ show_search_bar: show_search_bar?,
70
+ }
71
+ end
72
+ ```
73
+
74
+ What the above does is applying a few transforms
75
+ to the variable `resources`, filtering it, applying includes for associations,
76
+ ordering the results, paginating them, and finally handing them over to the
77
+ template in order to be rendered. All this is pretty standard Rails, although
78
+ split into individual steps that can be overriden by developers in order
79
+ to add customizations, and ultimately wrapped in an instance of
80
+ `Administrate::Page::Collection` which will read your dashboard definitions
81
+ and figure out what fields you want displayed.
82
+
83
+ It is the filtering part where the search is implemented. You will notice the
84
+ `filter_resources` method, which takes a parameter `search_term`. This is what
85
+ this method looks like at the moment:
86
+
87
+ ```ruby
88
+ def filter_resources(resources, search_term:)
89
+ Administrate::Search.new(
90
+ resources,
91
+ dashboard,
92
+ search_term,
93
+ ).run
94
+ end
95
+ ```
96
+
97
+ The class `Administrate::Search` implements the default search facilities
98
+ within Administrate... but you do not have to worry about it! You can ignore
99
+ it and implement your own search in `filter_resources`. For example, you
100
+ could write your own version in your controller, to override Administrate's
101
+ own. Something like this:
102
+
103
+ ```ruby
104
+ def filter_resources(resources, search_term:)
105
+ resources.where(first_name: search_term)
106
+ .or(People.where(last_name: search_term))
107
+ end
108
+ ```
109
+
110
+ It can be as complex (or simple) as you want, as long as the return value
111
+ of the method is an ActiveRecord relation.
112
+
113
+ What if you do not want to search in the DB? For example, say that your records
114
+ are indexed by Elasticsearch or something like that. You can still search
115
+ in your external index and convert the results to an ActiveRecord relation.
116
+ Here's an example:
117
+
118
+ ```ruby
119
+ def filter_resources(resources, search_term:)
120
+ # Run the search term through your search facility
121
+ results = MySuperDuperSearchSystem.search_people(search_term)
122
+
123
+ # Collect the ids of the results. This assumes that they will
124
+ # be the same ones as in the DB.
125
+ record_ids = results.entries.map(&:id)
126
+
127
+ # Use the ids to create an ActiveRecord relation and return it
128
+ People.where(id: record_ids)
129
+ end
130
+ ```
131
+
132
+ Note though: the records must still exist in the DB. Administrate does
133
+ require ActiveRecord in order to show tables, and to display, create and edit
134
+ records.
135
+
136
+ ## A working example
137
+
138
+ The [Administrate demo app](https://administrate-demo.herokuapp.com/admin)
139
+ includes an example of custom search in the "Log Entries" dashboard.
140
+ In this app, each `LogEntry` instance has a polymorphic `belongs_to`
141
+ association to a `:logeable`. Logeables are other models for which logs can be
142
+ created. At the moment these are `Order` and `Customer`.
143
+
144
+ Administrate's default search is not able to search across polymorphic
145
+ associations, and therefore it is not possible to search logs by the contents
146
+ of their logeables. Fortunately this can be fixed with a custom search. This is
147
+ done by implementing `Admin::LogEntriesController#filter_resources` to override
148
+ the default search. You can see the code at
149
+ https://github.com/thoughtbot/administrate/blob/main/spec/example_app/app/controllers/admin/log_entries_controller.rb
@@ -0,0 +1,21 @@
1
+ ---
2
+ title: Hiding Dashboards from the Sidebar
3
+ ---
4
+
5
+ Resources can be removed from the sidebar by removing their `index` action
6
+ from the routes. For example:
7
+
8
+ ```ruby
9
+ # config/routes.rb
10
+ Rails.application.routes.draw do
11
+ namespace :admin do
12
+ resources :line_items, except: :index
13
+ resources :orders
14
+ resources :products
15
+ root to: "customers#index"
16
+ end
17
+ end
18
+ ```
19
+
20
+ In this case, only Orders and Products will appear in the sidebar, while
21
+ Line Items can still appear as an association.
@@ -0,0 +1,27 @@
1
+ ---
2
+ title: Scoping HasMany Relations
3
+ ---
4
+
5
+ To show a subset of a has_many relationship, create a new [has_many](https://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many) relationship in your model (using the `scope` argument) and add it to the model's dashboard.
6
+
7
+ ## Creating a scoped has_many relationship
8
+
9
+ Models can define subsets of a `has_many` relationship by passing a callable (i.e. proc or lambda) as its second argument.
10
+
11
+ ```ruby
12
+ class Customer < ApplicationRecord
13
+ has_many :orders
14
+ has_many :processed_orders, ->{ where(processed: true) }, class_name: "Order"
15
+ ```
16
+
17
+ Since ActiveRecord infers the class name from the first argument, the new `has_many` relation needs to specify the model using the `class_name` option.
18
+
19
+ ## Add new relationship to dashboard
20
+
21
+ Your new scoped relation can be used in the dashboard just like the original `HasMany`.
22
+
23
+ ```ruby
24
+ ATTRIBUTE_TYPES = {
25
+ orders: Field::HasMany,
26
+ processed_orders: Field::HasMany
27
+ ```
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: Switching templates with view variants
3
+ ---
4
+
5
+ You can switch to different templates using Rails' support for [view
6
+ variants][], which can be used to override the template used inside the
7
+ controller.
8
+
9
+ By setting the `request.variant` option to any value (in this case, `:admin`)
10
+ at any point in any controller, you can add a new variant to Rails' template
11
+ lookup tree (in this case, `.html+admin.erb`).
12
+
13
+ For example, to add a button to become the admin to view certain functionality:
14
+
15
+ ```ruby
16
+ class CustomersController < Admin::ApplicationController
17
+ before_action :with_variant, only: %i[index]
18
+
19
+ private
20
+
21
+ def with_variant
22
+ if @current_user.admin?
23
+ request.variant = :admin
24
+ end
25
+ end
26
+ end
27
+ ```
28
+
29
+ ```erb
30
+ <!-- app/views/admin/customers/_index_header.html.erb -->
31
+ <p class="identity__banner">
32
+ You are logged in as <em><%= pundit_user.name %></em>.
33
+ <%= link_to("Become the Admin", become_admin_customer_path("admin"),
34
+ class: "identity__become-action")%>
35
+ </p>
36
+ ```
37
+
38
+ ```erb
39
+ <!-- app/views/admin/customers/_index_header.html+admin.erb -->
40
+ <p class="identity__banner identity__banner--admin">
41
+ You are logged in as <em><%= pundit_user.name %></em>.
42
+ </p>
43
+ ```
44
+
45
+ [view variants]: https://guides.rubyonrails.org/layouts_and_rendering.html#the-variants-option
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: Guides
3
+ ---
4
+
5
+ - [Hiding Dashboards from the Sidebar](./guides/hiding_dashboards_from_sidebar)
6
+ - [Customising the search](./guides/customising_search)
7
+ - [Scoping HasMany Relations](./guides/scoping_has_many_relations.md)
8
+ - [Switching templates with view variants](./guides/switching_templates_with_view_variants.md)
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: Migrating to v1
3
+ ---
4
+
5
+ In the release of v1.0.0, we [began bundling assets in the gem itself][2397].
6
+ In the future, this should mean that any changes made to assets (coming
7
+ from you or from Administrate updates) should not have an effect on you.
8
+ However, this is quite a big change and so you might find some problems.
9
+
10
+ As with most upgrades, if you're upgrading between versions with changes to the
11
+ templates, and if you've customised them, you may need to apply recent changes.
12
+ You can see those which changed in the [CHANGELOG][].
13
+
14
+ This applies to both modified files in `app/views/admin` and `app/views/fields`
15
+ if you have your own Field classes defined. A good way is to use the same
16
+ command to generate the view as for the earlier version:
17
+ `rails generate administrate:views:ACTION MyModel`
18
+ noting the changes and re-applying the modifications
19
+
20
+ [2397]: https://github.com/thoughtbot/administrate/pull/2397
21
+ [CHANGELOG]: https://github.com/thoughtbot/administrate/blob/main/CHANGELOG.md
22
+
23
+ ## Reported issues
24
+
25
+ ### Removal of the `sprockets-rails` transitive dependency
26
+
27
+ [Issue][2514]
28
+
29
+ Previously, Administrate depended on [`sprockets-rails`][], if you have a
30
+ dependency which requires this, you may now need to add a direct dependency on
31
+ your application.
32
+
33
+ [2514]: https://github.com/thoughtbot/administrate/issues/2514
34
+ [`sprockets-rails`]: https://rubygems.org/gems/sprockets-rails
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: Rails API
3
+ ---
4
+
5
+ Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
6
+ we still want to have an admin.
7
+
8
+ To get this working, we recommend updating this config:
9
+
10
+ ```ruby
11
+ # config/application.rb
12
+ config.api_only = false
13
+ ```
14
+
15
+ That means, when your app _boots_, we'll have access to flashes and such. We
16
+ also don't use your `ApplicationController`. Instead, Administrate provides its
17
+ own. Meaning you're free to specify `ActionController::API` as your parent
18
+ controller to make sure no flash, session, or cookie middleware is used by your
19
+ API.
20
+
21
+ Alternatively, if your application needs to have `config.api_only = true`, we
22
+ recommend you add the following lines to your `config/application.rb`
23
+
24
+ ```ruby
25
+ # Enable Flash, Cookies, MethodOverride for Administrate Gem
26
+ config.middleware.use ActionDispatch::Flash
27
+ config.session_store :cookie_store
28
+ config.middleware.use ActionDispatch::Cookies
29
+ config.middleware.use ActionDispatch::Session::CookieStore, config.session_options
30
+ config.middleware.use ::Rack::MethodOverride
31
+ ```
32
+
33
+ You must also ensure that all the required controller actions are available
34
+ and accessible as routes since generators in API-only applications only
35
+ generate some of the required actions. Here is an example:
36
+
37
+ ```ruby
38
+ # routes.rb
39
+ namespace :admin do
40
+ resources :name, only: %i(index show new create edit update destroy)
41
+ end
42
+
43
+ # names_controller.rb
44
+ # Ensure each of those methods are defined
45
+ ```