administrate 0.13.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/administrate/components/associative.js +5 -0
  3. data/app/assets/stylesheets/administrate/base/_tables.scss +3 -0
  4. data/app/assets/stylesheets/administrate/components/_attributes.scss +3 -2
  5. data/app/assets/stylesheets/administrate/components/_buttons.scss +3 -0
  6. data/app/assets/stylesheets/administrate/components/_field-unit.scss +4 -0
  7. data/app/assets/stylesheets/administrate/components/_flashes.scss +0 -8
  8. data/app/assets/stylesheets/administrate/components/_main-content.scss +1 -0
  9. data/app/assets/stylesheets/administrate/library/_variables.scss +10 -8
  10. data/app/controllers/administrate/application_controller.rb +47 -13
  11. data/app/helpers/administrate/application_helper.rb +27 -28
  12. data/app/views/administrate/application/_collection.html.erb +24 -26
  13. data/app/views/administrate/application/_collection_header_actions.html.erb +4 -0
  14. data/app/views/administrate/application/_collection_item_actions.html.erb +17 -0
  15. data/app/views/administrate/application/_flashes.html.erb +1 -0
  16. data/app/views/administrate/application/_form.html.erb +2 -2
  17. data/app/views/administrate/application/_icons.html.erb +1 -1
  18. data/app/views/administrate/application/_index_header.html.erb +28 -0
  19. data/app/views/administrate/application/_navigation.html.erb +4 -4
  20. data/app/views/administrate/application/index.html.erb +9 -29
  21. data/app/views/administrate/application/show.html.erb +1 -1
  22. data/app/views/fields/belongs_to/_form.html.erb +3 -3
  23. data/app/views/fields/belongs_to/_index.html.erb +1 -1
  24. data/app/views/fields/belongs_to/_show.html.erb +1 -1
  25. data/app/views/fields/has_one/_index.html.erb +1 -1
  26. data/app/views/fields/has_one/_show.html.erb +4 -4
  27. data/app/views/fields/number/_form.html.erb +1 -1
  28. data/app/views/fields/polymorphic/_show.html.erb +1 -1
  29. data/app/views/fields/select/_form.html.erb +23 -9
  30. data/app/views/fields/time/_form.html.erb +3 -2
  31. data/app/views/fields/time/_index.html.erb +3 -1
  32. data/app/views/fields/time/_show.html.erb +3 -1
  33. data/app/views/fields/url/_index.html.erb +1 -1
  34. data/app/views/fields/url/_show.html.erb +1 -1
  35. data/app/views/layouts/administrate/application.html.erb +1 -0
  36. data/config/locales/administrate.ar.yml +2 -0
  37. data/config/locales/administrate.bs.yml +2 -0
  38. data/config/locales/administrate.ca.yml +2 -0
  39. data/config/locales/administrate.da.yml +2 -0
  40. data/config/locales/administrate.de.yml +2 -0
  41. data/config/locales/administrate.en.yml +2 -0
  42. data/config/locales/administrate.es.yml +2 -0
  43. data/config/locales/administrate.fi.yml +30 -0
  44. data/config/locales/administrate.fr.yml +4 -2
  45. data/config/locales/administrate.id.yml +2 -0
  46. data/config/locales/administrate.it.yml +2 -0
  47. data/config/locales/administrate.ja.yml +2 -0
  48. data/config/locales/administrate.ko.yml +2 -0
  49. data/config/locales/administrate.nl.yml +7 -5
  50. data/config/locales/administrate.pl.yml +2 -0
  51. data/config/locales/administrate.pt-BR.yml +4 -2
  52. data/config/locales/administrate.pt.yml +4 -2
  53. data/config/locales/administrate.ru.yml +2 -0
  54. data/config/locales/{administrate.al.yml → administrate.sq.yml} +3 -1
  55. data/config/locales/administrate.sv.yml +2 -0
  56. data/config/locales/administrate.tr.yml +30 -0
  57. data/config/locales/administrate.uk.yml +2 -0
  58. data/config/locales/administrate.vi.yml +2 -0
  59. data/config/locales/administrate.zh-CN.yml +2 -0
  60. data/config/locales/administrate.zh-TW.yml +2 -0
  61. data/config/unicorn.rb +8 -13
  62. data/docs/adding_controllers_without_related_model.md +52 -0
  63. data/docs/customizing_controller_actions.md +32 -0
  64. data/docs/customizing_dashboards.md +81 -23
  65. data/docs/customizing_page_views.md +15 -3
  66. data/docs/extending_administrate.md +27 -0
  67. data/docs/getting_started.md +27 -5
  68. data/docs/guides/hiding_dashboards_from_sidebar.md +19 -0
  69. data/docs/guides.md +5 -0
  70. data/lib/administrate/base_dashboard.rb +34 -12
  71. data/lib/administrate/custom_dashboard.rb +15 -0
  72. data/lib/administrate/engine.rb +7 -0
  73. data/lib/administrate/field/associative.rb +49 -5
  74. data/lib/administrate/field/base.rb +30 -0
  75. data/lib/administrate/field/belongs_to.rb +13 -3
  76. data/lib/administrate/field/deferred.rb +22 -3
  77. data/lib/administrate/field/has_many.rb +15 -2
  78. data/lib/administrate/field/has_one.rb +28 -8
  79. data/lib/administrate/field/number.rb +19 -2
  80. data/lib/administrate/field/polymorphic.rb +2 -2
  81. data/lib/administrate/field/select.rb +10 -1
  82. data/lib/administrate/field/time.rb +11 -0
  83. data/lib/administrate/namespace.rb +5 -1
  84. data/lib/administrate/order.rb +3 -1
  85. data/lib/administrate/page/base.rb +1 -1
  86. data/lib/administrate/page/form.rb +10 -3
  87. data/lib/administrate/resource_resolver.rb +2 -2
  88. data/lib/administrate/search.rb +47 -36
  89. data/lib/administrate/version.rb +1 -1
  90. data/lib/administrate/view_generator.rb +7 -1
  91. data/lib/administrate.rb +19 -0
  92. data/lib/generators/administrate/dashboard/dashboard_generator.rb +18 -14
  93. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +2 -2
  94. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +3 -3
  95. data/lib/generators/administrate/install/install_generator.rb +37 -1
  96. data/lib/generators/administrate/install/templates/application_controller.rb.erb +1 -1
  97. data/lib/generators/administrate/routes/routes_generator.rb +3 -13
  98. data/lib/generators/administrate/views/views_generator.rb +5 -4
  99. metadata +25 -44
  100. data/app/assets/javascripts/administrate/components/has_many_form.js +0 -3
  101. data/docs/contributing.md +0 -1
@@ -4,7 +4,7 @@
4
4
  This partial renders a has_one relationship,
5
5
  to be displayed on a resource's show page.
6
6
 
7
- All fields of has_one relationship would be rendered
7
+ All show page attributes of has_one relationship would be rendered
8
8
 
9
9
  ## Local variables:
10
10
 
@@ -15,7 +15,7 @@ All fields of has_one relationship would be rendered
15
15
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasOne
16
16
  %>
17
17
 
18
- <% if field.data %>
18
+ <% if field.linkable? %>
19
19
  <fieldset class="attribute--nested">
20
20
  <legend>
21
21
  <%= link_to(
@@ -23,7 +23,7 @@ All fields of has_one relationship would be rendered
23
23
  [namespace, field.data],
24
24
  ) %>
25
25
  </legend>
26
- <% field.nested_form.attributes.each do |attribute| -%>
26
+ <% field.nested_show.attributes.each do |attribute| -%>
27
27
  <div>
28
28
  <dt class="attribute-label">
29
29
  <%= t(
@@ -32,7 +32,7 @@ All fields of has_one relationship would be rendered
32
32
  ) %>
33
33
  </dt>
34
34
  <dd class="attribute-data attribute-data--<%= attribute.html_class %>">
35
- <%= attribute.data %>
35
+ <%= render_field attribute, { page: page } %>
36
36
  </dd>
37
37
  </div>
38
38
  <% end -%>
@@ -19,5 +19,5 @@ By default, the input is a text field.
19
19
  <%= f.label field.attribute %>
20
20
  </div>
21
21
  <div class="field-unit__field">
22
- <%= f.text_field field.attribute %>
22
+ <%= f.number_field field.attribute, step: "any" %>
23
23
  </div>
@@ -17,7 +17,7 @@ By default, the relationship is rendered as a link to the associated object.
17
17
  %>
18
18
 
19
19
  <% if field.data %>
20
- <% if valid_action?(:show, field.attribute) %>
20
+ <% if valid_action?(:show, field.data.class) %>
21
21
  <%= link_to(
22
22
  field.display_associated_resource,
23
23
  [namespace, field.data],
@@ -19,13 +19,27 @@ to be displayed on a resource's edit form page.
19
19
  <%= f.label field.attribute %>
20
20
  </div>
21
21
  <div class="field-unit__field">
22
- <%= f.select(
23
- field.attribute,
24
- options_from_collection_for_select(
25
- field.selectable_options,
26
- :to_s,
27
- :to_s,
28
- field.data.presence,
29
- )
30
- ) %>
22
+ <% if field.selectable_options.first&.is_a?(Array) %>
23
+ <%= f.select(
24
+ field.attribute,
25
+ options_from_collection_for_select(
26
+ field.selectable_options,
27
+ :last,
28
+ :first,
29
+ field.data,
30
+ ),
31
+ include_blank: field.include_blank_option
32
+ ) %>
33
+ <% else %>
34
+ <%= f.select(
35
+ field.attribute,
36
+ options_from_collection_for_select(
37
+ field.selectable_options,
38
+ :to_s,
39
+ :to_s,
40
+ field.data,
41
+ ),
42
+ include_blank: field.include_blank_option
43
+ ) %>
44
+ <% end %>
31
45
  </div>
@@ -2,7 +2,7 @@
2
2
  # Time Form Partial
3
3
 
4
4
  This partial renders an input element for time attributes.
5
- By default, the input is a select field for the time attributes.
5
+ By default, the input is a text field that is augmented with [DateTimePicker].
6
6
 
7
7
  ## Local variables:
8
8
 
@@ -12,11 +12,12 @@ By default, the input is a select field for the time attributes.
12
12
  An instance of [Administrate::Field::Time][1].
13
13
  A wrapper around the tmie attributes pulled from the model.
14
14
 
15
+ [DateTimePicker]: https://github.com/Eonasdan/bootstrap-datetimepicker
15
16
  %>
16
17
 
17
18
  <div class="field-unit__label">
18
19
  <%= f.label field.attribute %>
19
20
  </div>
20
21
  <div class="field-unit__field">
21
- <%= f.text_field field.attribute, data: { type: 'time' } %>
22
+ <%= f.text_field field.attribute, data: { type: 'time' }, value: field.data&.strftime("%H:%M:%S") %>
22
23
  </div>
@@ -14,4 +14,6 @@ By default, the attribute is rendered as a text tag.
14
14
 
15
15
  %>
16
16
 
17
- <%= field.data.strftime("%I:%M%p").to_s %>
17
+ <% if field.data %>
18
+ <%= field.time %>
19
+ <% end %>
@@ -14,4 +14,6 @@ By default, the attribute is rendered as a text tag.
14
14
 
15
15
  %>
16
16
 
17
- <%= field.data.strftime("%I:%M%p").to_s %>
17
+ <% if field.data %>
18
+ <%= field.time %>
19
+ <% end %>
@@ -1,7 +1,7 @@
1
1
  <%#
2
2
  # Url Index Partial
3
3
 
4
- This partial renders an email address,
4
+ This partial renders a URL address,
5
5
  to be displayed on a resource's index page.
6
6
 
7
7
  By default, the value is rendered as an `a` element.
@@ -1,7 +1,7 @@
1
1
  <%#
2
2
  # Url Show Partial
3
3
 
4
- This partial renders an email address,
4
+ This partial renders a URL address,
5
5
  to be displayed on a resource's show page.
6
6
 
7
7
  By default, the value is rendered as an `a` element.
@@ -23,6 +23,7 @@ By default, it renders:
23
23
  </title>
24
24
  <%= render "stylesheet" %>
25
25
  <%= csrf_meta_tags %>
26
+ <%= csp_meta_tag if defined?(csp_meta_tag) %>
26
27
  </head>
27
28
  <body>
28
29
  <%= render "icons" %>
@@ -23,6 +23,8 @@ ar:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: العودة إلى التطبيق
26
28
  search:
27
29
  clear: مسح البحث
28
30
  label: بحث %{resource}
@@ -22,6 +22,8 @@ bs:
22
22
  form:
23
23
  error: error
24
24
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
25
+ navigation:
26
+ back_to_app: Natrag na aplikaciju
25
27
  search:
26
28
  clear: Izbriši pretraživanje
27
29
  label: Pretraga %{resource}
@@ -23,6 +23,8 @@ ca:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} han impedit que %{resource_name} es guardés amb èxit:"
26
+ navigation:
27
+ back_to_app: Torna a l'aplicació
26
28
  search:
27
29
  clear: Esborrar la cerca
28
30
  label: Cerca %{resource}
@@ -23,6 +23,8 @@ da:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Tilbage til app
26
28
  search:
27
29
  clear: Ryd søgning
28
30
  label: Søg %{resource}
@@ -23,6 +23,8 @@ de:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} haben das Speichern dieses %{resource_name} verhindert:"
26
+ navigation:
27
+ back_to_app: Zurück zur App
26
28
  search:
27
29
  clear: Suche zurücksetzen
28
30
  label: "%{resource} durchsuchen"
@@ -23,6 +23,8 @@ en:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Back to app
26
28
  search:
27
29
  clear: Clear search
28
30
  label: Search %{resource}
@@ -23,6 +23,8 @@ es:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} no permitieron guardar este %{resource_name}:"
26
+ navigation:
27
+ back_to_app: Regresar a la aplicación
26
28
  search:
27
29
  clear: Borrar búsqueda
28
30
  label: Buscar %{resource}
@@ -0,0 +1,30 @@
1
+ ---
2
+ fi:
3
+ administrate:
4
+ actions:
5
+ confirm: Oletko varma?
6
+ destroy: Poista
7
+ edit: Muokkaa
8
+ edit_resource: Muokkaa %{name}
9
+ show_resource: Näytä %{name}
10
+ new_resource: Uusi %{name}
11
+ back: Takaisin
12
+ controller:
13
+ create:
14
+ success: "%{resource} luotiin onnistuneesti."
15
+ destroy:
16
+ success: "%{resource} poistettiin onnistuneesti."
17
+ update:
18
+ success: "%{resource} päivitettiin onnistuneesti."
19
+ fields:
20
+ has_many:
21
+ more: Näytetään %{count}/%{total_count}
22
+ none: Ei yhtään
23
+ form:
24
+ error: virhe
25
+ errors: "%{pluralized_errors} estivät tätä %{resource_name} tallentumasta:"
26
+ navigation:
27
+ back_to_app: Takaisin sovellukseen
28
+ search:
29
+ clear: Tyhjennä haku
30
+ label: Etsi %{resource}
@@ -2,7 +2,7 @@
2
2
  fr:
3
3
  administrate:
4
4
  actions:
5
- confirm: Êtes-vous sûr ?
5
+ confirm: Êtes-vous sûr(e) ?
6
6
  destroy: Supprimer
7
7
  edit: Modifier
8
8
  edit_resource: Modifier %{name}
@@ -22,7 +22,9 @@ fr:
22
22
  none: Aucun
23
23
  form:
24
24
  error: erreur
25
- errors: "%{pluralized_errors} ont empêchés %{resource_name} d'être sauvergardé :"
25
+ errors: "%{pluralized_errors} ont empêché %{resource_name} d'être sauvegardé(e) :"
26
+ navigation:
27
+ back_to_app: Retour à l'application
26
28
  search:
27
29
  clear: Effacer la recherche
28
30
  label: Chercher %{resource}
@@ -23,6 +23,8 @@ id:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} membuat %{resource_name} tidak bisa tersimpan:"
26
+ navigation:
27
+ back_to_app: Kembali ke aplikasi
26
28
  search:
27
29
  clear: Kosongkan pencarian
28
30
  label: Cari %{resource}
@@ -23,6 +23,8 @@ it:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Torna all'app
26
28
  search:
27
29
  clear: Cancella ricerca
28
30
  label: Ricerca %{resource}
@@ -23,6 +23,8 @@ ja:
23
23
  form:
24
24
  error: エラー
25
25
  errors: "%{pluralized_errors}のため%{resource_name}を保存できません。"
26
+ navigation:
27
+ back_to_app: アプリに戻る
26
28
  search:
27
29
  clear: 検索をクリアする
28
30
  label: サーチ %{resource}
@@ -23,6 +23,8 @@ ko:
23
23
  form:
24
24
  error: 에러
25
25
  errors: "%{pluralized_errors}로 인하여 %{resource_name}을(를) 저장하는데 실패하였습니다."
26
+ navigation:
27
+ back_to_app: 앱으로 돌아 가기
26
28
  search:
27
29
  clear: 검색 초기화
28
30
  label: "%{resource} 검색"
@@ -11,18 +11,20 @@ nl:
11
11
  back: Terug
12
12
  controller:
13
13
  create:
14
- success: "%{resource} was succesvol aangemaakt."
14
+ success: "%{resource} is succesvol aangemaakt."
15
15
  destroy:
16
- success: "%{resource} was succesvol verwijderd."
16
+ success: "%{resource} is succesvol verwijderd."
17
17
  update:
18
- success: "%{resource} was succesvol geupdated."
18
+ success: "%{resource} is succesvol geupdated."
19
19
  fields:
20
20
  has_many:
21
21
  more: Resultaat %{count} van %{total_count}
22
22
  none: Geen
23
23
  form:
24
24
  error: error
25
- errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
25
+ errors: "%{pluralized_errors} maakten het onmogelijk %{resource_name} op:"
26
+ navigation:
27
+ back_to_app: Terug naar app
26
28
  search:
27
- clear: CDuidelijke zoek
29
+ clear: Wissen
28
30
  label: Zoeken %{resource}
@@ -23,6 +23,8 @@ pl:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Powrót do aplikacji
26
28
  search:
27
29
  clear: Wyczyść wyszukiwanie
28
30
  label: Szukanie %{resource}
@@ -22,8 +22,10 @@ pt-BR:
22
22
  more: "Exibindo %{count} de %{total_count}"
23
23
  none: Nenhum
24
24
  form:
25
- error: error
26
- errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
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: error
26
- errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
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}
@@ -23,6 +23,8 @@ ru:
23
23
  form:
24
24
  error: Ошибка
25
25
  errors: "При сохранении %{resource_name} произошли ошибки:"
26
+ navigation:
27
+ back_to_app: Вернуться в приложение
26
28
  search:
27
29
  clear: Очистить поиск
28
30
  label: Поиск %{resource}
@@ -1,5 +1,5 @@
1
1
  ---
2
- al:
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}
@@ -23,6 +23,8 @@ sv:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Tillbaka till appen
26
28
  search:
27
29
  clear: Rensa sökningen
28
30
  label: Sök %{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"
@@ -23,6 +23,8 @@ uk:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Повернутися до програми
26
28
  search:
27
29
  clear: Очистити пошук
28
30
  label: пошук %{resource}
@@ -23,6 +23,8 @@ vi:
23
23
  form:
24
24
  error: error
25
25
  errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
26
+ navigation:
27
+ back_to_app: Quay lại ứng dụng
26
28
  search:
27
29
  clear: Tìm kiếm rõ ràng
28
30
  label: Tìm kiếm %{resource}
@@ -23,6 +23,8 @@ zh-CN:
23
23
  form:
24
24
  error: 错误
25
25
  errors: "%{resource_name} 保存前出现了 %{pluralized_errors} 个错误:"
26
+ navigation:
27
+ back_to_app: 返回应用
26
28
  search:
27
29
  clear: 清除搜索
28
30
  label: 搜索 %{resource}
@@ -23,6 +23,8 @@ zh-TW:
23
23
  form:
24
24
  error: 錯誤
25
25
  errors: "%{pluralized_errors} 導致此 %{resource_name} 不能被儲存:"
26
+ navigation:
27
+ back_to_app: 返回首頁
26
28
  search:
27
29
  clear: 清除搜尋
28
30
  label: 搜尋 %{resource}
data/config/unicorn.rb CHANGED
@@ -1,30 +1,25 @@
1
1
  # https://devcenter.heroku.com/articles/rails-unicorn
2
2
 
3
- worker_processes (ENV["UNICORN_WORKERS"] || 3).to_i
4
- timeout (ENV["UNICORN_TIMEOUT"] || 15).to_i
3
+ worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
4
+ timeout 15
5
5
  preload_app true
6
6
 
7
7
  before_fork do |_server, _worker|
8
8
  Signal.trap "TERM" do
9
- puts "Unicorn master intercepting TERM, sending myself QUIT instead"
9
+ puts "Unicorn master intercepting TERM and sending myself QUIT instead"
10
10
  Process.kill "QUIT", Process.pid
11
11
  end
12
12
 
13
- if defined? ActiveRecord::Base
13
+ defined?(ActiveRecord::Base) &&
14
14
  ActiveRecord::Base.connection.disconnect!
15
- end
16
15
  end
17
16
 
18
17
  after_fork do |_server, _worker|
19
18
  Signal.trap "TERM" do
20
- puts "Unicorn worker intercepting TERM, waiting for master to send QUIT"
19
+ puts "Unicorn worker intercepting TERM and doing nothing. " \
20
+ "Wait for master to send QUIT"
21
21
  end
22
22
 
23
- if defined? ActiveRecord::Base
24
- config = ActiveRecord::Base.configurations[Rails.env] ||
25
- Rails.application.config.database_configuration[Rails.env]
26
- config["reaping_frequency"] = (ENV["DB_REAPING_FREQUENCY"] || 10).to_i
27
- config["pool"] = (ENV["DB_POOL"] || 2).to_i
28
- ActiveRecord::Base.establish_connection(config)
29
- end
23
+ defined?(ActiveRecord::Base) &&
24
+ ActiveRecord::Base.establish_connection
30
25
  end
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: Adding Controllers without a related Model
3
+ ---
4
+
5
+ Sometimes you may want to add a custom controller that has no resource
6
+ related to it (for example for a statistics page).
7
+
8
+ To do that, you must define an `index` route, as only controllers with index
9
+ routes are displayed in the sidebar and then add a custom dashboard:
10
+
11
+ ```erb
12
+ # app/views/admin/stats/index.html.erb
13
+
14
+ <div style="padding: 20px">
15
+ <h1>Stats</h1>
16
+ <br>
17
+ <p><b>Total Customers:</b> <%= @stats[:customer_count] %></h1>
18
+ <br>
19
+ <p><b>Total Orders:</b> <%= @stats[:order_count] %></h1>
20
+ </div>
21
+ ```
22
+
23
+ ```ruby
24
+ # app/dashboards/stat_dashboard.rb
25
+ require "administrate/custom_dashboard"
26
+
27
+ class StatDashboard < Administrate::CustomDashboard
28
+ resource "Stats" # used by administrate in the views
29
+ end
30
+ ```
31
+
32
+ ```ruby
33
+ # app/controllers/admin/stats_controller.rb
34
+ module Admin
35
+ class StatsController < Admin::ApplicationController
36
+ def index
37
+ @stats = {
38
+ customer_count: Customer.count,
39
+ order_count: Order.count,
40
+ }
41
+ end
42
+ end
43
+ end
44
+ ```
45
+
46
+ ```ruby
47
+ # config/routes.rb
48
+ namespace :admin do
49
+ # ...
50
+ resources :stats, only: [:index]
51
+ end
52
+ ```
@@ -56,3 +56,35 @@ end
56
56
  ```
57
57
 
58
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
+ ```