semantic-administrate 0.1.0

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 (174) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +32 -0
  3. data/app/assets/fonts/administrate/semantic-ui/icons.eot +0 -0
  4. data/app/assets/fonts/administrate/semantic-ui/icons.otf +0 -0
  5. data/app/assets/fonts/administrate/semantic-ui/icons.svg +2671 -0
  6. data/app/assets/fonts/administrate/semantic-ui/icons.ttf +0 -0
  7. data/app/assets/fonts/administrate/semantic-ui/icons.woff +0 -0
  8. data/app/assets/fonts/administrate/semantic-ui/icons.woff2 +0 -0
  9. data/app/assets/images/administrate/semantic-ui/flags.png +0 -0
  10. data/app/assets/javascripts/administrate/application.js +7 -0
  11. data/app/assets/javascripts/administrate/components/date_time_picker.js +6 -0
  12. data/app/assets/javascripts/administrate/components/has_many_form.js +3 -0
  13. data/app/assets/javascripts/administrate/components/table.js +23 -0
  14. data/app/assets/javascripts/administrate/vendor/semantic-ui.js +22943 -0
  15. data/app/assets/stylesheets/administrate/application.scss +27 -0
  16. data/app/assets/stylesheets/administrate/base/_forms.scss +106 -0
  17. data/app/assets/stylesheets/administrate/base/_layout.scss +10 -0
  18. data/app/assets/stylesheets/administrate/base/_lists.scss +19 -0
  19. data/app/assets/stylesheets/administrate/base/_typography.scss +48 -0
  20. data/app/assets/stylesheets/administrate/components/_app-container.scss +27 -0
  21. data/app/assets/stylesheets/administrate/components/_attributes.scss +34 -0
  22. data/app/assets/stylesheets/administrate/components/_buttons.scss +43 -0
  23. data/app/assets/stylesheets/administrate/components/_cells.scss +59 -0
  24. data/app/assets/stylesheets/administrate/components/_field-unit.scss +36 -0
  25. data/app/assets/stylesheets/administrate/components/_flashes.scss +28 -0
  26. data/app/assets/stylesheets/administrate/components/_form-actions.scss +3 -0
  27. data/app/assets/stylesheets/administrate/components/_main-content.scss +42 -0
  28. data/app/assets/stylesheets/administrate/components/_pagination.scss +18 -0
  29. data/app/assets/stylesheets/administrate/components/_search.scss +45 -0
  30. data/app/assets/stylesheets/administrate/components/nav-drawer.scss +156 -0
  31. data/app/assets/stylesheets/administrate/library/_clearfix.scss +7 -0
  32. data/app/assets/stylesheets/administrate/library/_data-label.scss +8 -0
  33. data/app/assets/stylesheets/administrate/library/_variables.scss +65 -0
  34. data/app/assets/stylesheets/administrate/vendor/semantic-ui.scss +37123 -0
  35. data/app/assets/stylesheets/docs.scss +93 -0
  36. data/app/controllers/administrate/application_controller.rb +162 -0
  37. data/app/helpers/administrate/application_helper.rb +51 -0
  38. data/app/views/administrate/application/_collection.html.erb +92 -0
  39. data/app/views/administrate/application/_flashes.html.erb +20 -0
  40. data/app/views/administrate/application/_form.html.erb +42 -0
  41. data/app/views/administrate/application/_icons.erb +13 -0
  42. data/app/views/administrate/application/_javascript.html.erb +21 -0
  43. data/app/views/administrate/application/_navigation.html.erb +19 -0
  44. data/app/views/administrate/application/_navigation_extra_links.html.erb +13 -0
  45. data/app/views/administrate/application/_navigation_footer.html.erb +44 -0
  46. data/app/views/administrate/application/_navigation_links.html.erb +16 -0
  47. data/app/views/administrate/application/_search.html.erb +25 -0
  48. data/app/views/administrate/application/_stylesheet.html.erb +14 -0
  49. data/app/views/administrate/application/edit.html.erb +36 -0
  50. data/app/views/administrate/application/index.html.erb +63 -0
  51. data/app/views/administrate/application/new.html.erb +32 -0
  52. data/app/views/administrate/application/show.html.erb +49 -0
  53. data/app/views/fields/belongs_to/_form.html.erb +26 -0
  54. data/app/views/fields/belongs_to/_index.html.erb +27 -0
  55. data/app/views/fields/belongs_to/_show.html.erb +27 -0
  56. data/app/views/fields/boolean/_form.html.erb +23 -0
  57. data/app/views/fields/boolean/_index.html.erb +19 -0
  58. data/app/views/fields/boolean/_show.html.erb +19 -0
  59. data/app/views/fields/date_time/_form.html.erb +24 -0
  60. data/app/views/fields/date_time/_index.html.erb +21 -0
  61. data/app/views/fields/date_time/_show.html.erb +21 -0
  62. data/app/views/fields/email/_form.html.erb +23 -0
  63. data/app/views/fields/email/_index.html.erb +18 -0
  64. data/app/views/fields/email/_show.html.erb +18 -0
  65. data/app/views/fields/has_many/_form.html.erb +29 -0
  66. data/app/views/fields/has_many/_index.html.erb +19 -0
  67. data/app/views/fields/has_many/_show.html.erb +35 -0
  68. data/app/views/fields/has_one/_form.html.erb +28 -0
  69. data/app/views/fields/has_one/_index.html.erb +23 -0
  70. data/app/views/fields/has_one/_show.html.erb +40 -0
  71. data/app/views/fields/number/_form.html.erb +23 -0
  72. data/app/views/fields/number/_index.html.erb +19 -0
  73. data/app/views/fields/number/_show.html.erb +19 -0
  74. data/app/views/fields/polymorphic/_form.html.erb +32 -0
  75. data/app/views/fields/polymorphic/_index.html.erb +24 -0
  76. data/app/views/fields/polymorphic/_show.html.erb +28 -0
  77. data/app/views/fields/select/_form.html.erb +31 -0
  78. data/app/views/fields/select/_index.html.erb +16 -0
  79. data/app/views/fields/select/_show.html.erb +16 -0
  80. data/app/views/fields/string/_form.html.erb +23 -0
  81. data/app/views/fields/string/_index.html.erb +18 -0
  82. data/app/views/fields/string/_show.html.erb +18 -0
  83. data/app/views/fields/text/_form.html.erb +22 -0
  84. data/app/views/fields/text/_index.html.erb +18 -0
  85. data/app/views/fields/text/_show.html.erb +19 -0
  86. data/app/views/layouts/administrate/application.html.erb +43 -0
  87. data/config/i18n-tasks.yml +18 -0
  88. data/config/locales/administrate.ar.yml +26 -0
  89. data/config/locales/administrate.bs.yml +25 -0
  90. data/config/locales/administrate.ca.yml +26 -0
  91. data/config/locales/administrate.da.yml +26 -0
  92. data/config/locales/administrate.de.yml +26 -0
  93. data/config/locales/administrate.en.yml +26 -0
  94. data/config/locales/administrate.es.yml +26 -0
  95. data/config/locales/administrate.fr.yml +26 -0
  96. data/config/locales/administrate.it.yml +26 -0
  97. data/config/locales/administrate.ja.yml +26 -0
  98. data/config/locales/administrate.ko.yml +26 -0
  99. data/config/locales/administrate.nl.yml +26 -0
  100. data/config/locales/administrate.pl.yml +26 -0
  101. data/config/locales/administrate.pt-BR.yml +27 -0
  102. data/config/locales/administrate.pt.yml +27 -0
  103. data/config/locales/administrate.ru.yml +26 -0
  104. data/config/locales/administrate.sv.yml +26 -0
  105. data/config/locales/administrate.uk.yml +26 -0
  106. data/config/locales/administrate.vi.yml +26 -0
  107. data/config/locales/administrate.zh-CN.yml +26 -0
  108. data/config/locales/administrate.zh-TW.yml +26 -0
  109. data/config/routes.rb +2 -0
  110. data/config/unicorn.rb +30 -0
  111. data/docs/adding_custom_field_types.md +79 -0
  112. data/docs/authentication.md +61 -0
  113. data/docs/customizing_attribute_partials.md +53 -0
  114. data/docs/customizing_controller_actions.md +42 -0
  115. data/docs/customizing_dashboards.md +202 -0
  116. data/docs/customizing_page_views.md +78 -0
  117. data/docs/getting_started.md +115 -0
  118. data/lib/administrate.rb +4 -0
  119. data/lib/administrate/base_dashboard.rb +72 -0
  120. data/lib/administrate/engine.rb +44 -0
  121. data/lib/administrate/field/associative.rb +33 -0
  122. data/lib/administrate/field/base.rb +54 -0
  123. data/lib/administrate/field/belongs_to.rb +36 -0
  124. data/lib/administrate/field/boolean.rb +15 -0
  125. data/lib/administrate/field/date_time.rb +21 -0
  126. data/lib/administrate/field/deferred.rb +35 -0
  127. data/lib/administrate/field/email.rb +11 -0
  128. data/lib/administrate/field/has_many.rb +87 -0
  129. data/lib/administrate/field/has_one.rb +27 -0
  130. data/lib/administrate/field/number.rb +35 -0
  131. data/lib/administrate/field/polymorphic.rb +51 -0
  132. data/lib/administrate/field/select.rb +21 -0
  133. data/lib/administrate/field/string.rb +21 -0
  134. data/lib/administrate/field/text.rb +21 -0
  135. data/lib/administrate/generator_helpers.rb +13 -0
  136. data/lib/administrate/namespace.rb +31 -0
  137. data/lib/administrate/namespace/resource.rb +28 -0
  138. data/lib/administrate/order.rb +45 -0
  139. data/lib/administrate/page.rb +4 -0
  140. data/lib/administrate/page/base.rb +35 -0
  141. data/lib/administrate/page/collection.rb +33 -0
  142. data/lib/administrate/page/form.rb +28 -0
  143. data/lib/administrate/page/show.rb +24 -0
  144. data/lib/administrate/resource_resolver.rb +43 -0
  145. data/lib/administrate/search.rb +47 -0
  146. data/lib/administrate/version.rb +3 -0
  147. data/lib/administrate/view_generator.rb +36 -0
  148. data/lib/generators/administrate/assets/assets_generator.rb +12 -0
  149. data/lib/generators/administrate/assets/javascripts_generator.rb +17 -0
  150. data/lib/generators/administrate/assets/stylesheets_generator.rb +17 -0
  151. data/lib/generators/administrate/dashboard/USAGE +9 -0
  152. data/lib/generators/administrate/dashboard/dashboard_generator.rb +141 -0
  153. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +21 -0
  154. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +56 -0
  155. data/lib/generators/administrate/field/field_generator.rb +31 -0
  156. data/lib/generators/administrate/field/templates/_form.html.erb +6 -0
  157. data/lib/generators/administrate/field/templates/_index.html.erb +1 -0
  158. data/lib/generators/administrate/field/templates/_show.html.erb +1 -0
  159. data/lib/generators/administrate/field/templates/field_object.rb.erb +7 -0
  160. data/lib/generators/administrate/install/install_generator.rb +49 -0
  161. data/lib/generators/administrate/install/templates/application_controller.rb.erb +21 -0
  162. data/lib/generators/administrate/routes/routes_generator.rb +91 -0
  163. data/lib/generators/administrate/routes/templates/routes.rb.erb +5 -0
  164. data/lib/generators/administrate/views/edit_generator.rb +16 -0
  165. data/lib/generators/administrate/views/field_generator.rb +50 -0
  166. data/lib/generators/administrate/views/form_generator.rb +15 -0
  167. data/lib/generators/administrate/views/index_generator.rb +16 -0
  168. data/lib/generators/administrate/views/layout_generator.rb +23 -0
  169. data/lib/generators/administrate/views/navigation_generator.rb +15 -0
  170. data/lib/generators/administrate/views/new_generator.rb +16 -0
  171. data/lib/generators/administrate/views/show_generator.rb +15 -0
  172. data/lib/generators/administrate/views/views_generator.rb +14 -0
  173. data/lib/tasks/administrate_tasks.rake +4 -0
  174. metadata +388 -0
@@ -0,0 +1,26 @@
1
+ ---
2
+ zh-TW:
3
+ administrate:
4
+ actions:
5
+ confirm: 確定?
6
+ destroy: 刪除
7
+ edit: 編輯
8
+ show: 檢視
9
+ new: 新增
10
+ back: 返回
11
+ controller:
12
+ create:
13
+ success: "已成功新增 %{resource}。"
14
+ destroy:
15
+ success: "已成功刪除 %{resource}。"
16
+ update:
17
+ success: "已成功更新 %{resource}。"
18
+ fields:
19
+ has_many:
20
+ more: 顯示 %{total_count} 筆中的 %{count} 筆資料
21
+ none: 無
22
+ has_one:
23
+ not_supported: 表單尚未支援 HasOne 關聯。
24
+ search:
25
+ clear: 清除搜索
26
+ label: 搜索 %{resource}
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Administrate::Engine.routes.draw do
2
+ end
data/config/unicorn.rb ADDED
@@ -0,0 +1,30 @@
1
+ # https://devcenter.heroku.com/articles/rails-unicorn
2
+
3
+ worker_processes (ENV["UNICORN_WORKERS"] || 3).to_i
4
+ timeout (ENV["UNICORN_TIMEOUT"] || 15).to_i
5
+ preload_app true
6
+
7
+ before_fork do |_server, _worker|
8
+ Signal.trap "TERM" do
9
+ puts "Unicorn master intercepting TERM, sending myself QUIT instead"
10
+ Process.kill "QUIT", Process.pid
11
+ end
12
+
13
+ if defined? ActiveRecord::Base
14
+ ActiveRecord::Base.connection.disconnect!
15
+ end
16
+ end
17
+
18
+ after_fork do |_server, _worker|
19
+ Signal.trap "TERM" do
20
+ puts "Unicorn worker intercepting TERM, waiting for master to send QUIT"
21
+ end
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
30
+ end
@@ -0,0 +1,79 @@
1
+ # Adding Custom Field Types
2
+
3
+ If your application deals with a nonstandard data type,
4
+ you can create an `Administrate::Field` object to help display
5
+ the custom data type across the dashboard.
6
+
7
+ `Administrate::Field` objects consist of two parts:
8
+ a Ruby class and associated views.
9
+
10
+ For example, let's create a `Field` that displays [Gravatars] based on an email.
11
+
12
+ [Gravatars]: https://gravatar.com/
13
+
14
+ First, we'll run a generator to set us up with the files we need:
15
+
16
+ ```bash
17
+ rails generate administrate:field gravatar
18
+ ```
19
+
20
+ This creates a few files:
21
+
22
+ - `app/fields/gravatar_field.rb`
23
+ - `app/views/fields/gravatar_field/_show.html.erb`
24
+ - `app/views/fields/gravatar_field/_index.html.erb`
25
+ - `app/views/fields/gravatar_field/_form.html.erb`
26
+
27
+ We can edit the `app/fields/gravatar_field.rb` to add some custom logic:
28
+
29
+ ```ruby
30
+ # app/fields/gravatar_field.rb
31
+ require 'digest/md5'
32
+
33
+ class GravatarField < Administrate::Field::Base
34
+ def gravatar_url
35
+ email_address = data.downcase
36
+ hash = Digest::MD5.hexdigest(email_address)
37
+ "http://www.gravatar.com/avatar/#{hash}"
38
+ end
39
+ end
40
+ ```
41
+
42
+ Next, we can customize the partials to display data how we'd like.
43
+ Open up the `app/views/fields/gravatar_field/_show.html.erb` partial.
44
+ By default, it looks like:
45
+
46
+ ```eruby
47
+ <%= field.to_s %>
48
+ ```
49
+
50
+ Since we want to display an image, we can change it to:
51
+
52
+ ```eruby
53
+ <%= image_tag field.gravatar_url %>
54
+ ```
55
+
56
+ You can customize the other generated partials in the same way
57
+ for custom behavior on the index and form pages.
58
+
59
+ ## Using your custom field
60
+
61
+ We need to tell Administrate which attributes we'd like to be displayed as a
62
+ gravatar image.
63
+
64
+ Open up a dashboard file, and add the gravatar field into the `ATTRIBUTE_TYPES`
65
+ hash. It should look something like:
66
+
67
+ ```ruby
68
+ class UserDashboard < Administrate::BaseDashboard
69
+ ATTRIBUTE_TYPES = {
70
+ created_at: Field::DateTime,
71
+ updated_at: Field::DateTime,
72
+ name: Field::String,
73
+ email: GravatarField, # Update this email to use your new field class
74
+ # ...
75
+ }
76
+ end
77
+ ```
78
+
79
+ [Customizing Attribute Partials]: /customizing_attribute_partials
@@ -0,0 +1,61 @@
1
+ # Authenticating admin users
2
+
3
+ Authentication is left for you to implement after you install Administrate into
4
+ your app. It's expected that you can plugin your existing authentication
5
+ system.
6
+
7
+ The base `Admin::ApplicationController` has a `TODO` to be completed:
8
+
9
+ ```ruby
10
+ class Admin::ApplicationController < Administrate::ApplicationController
11
+ before_action :authenticate_admin
12
+
13
+ def authenticate_admin
14
+ # TODO Add authentication logic here.
15
+ end
16
+ end
17
+ ```
18
+
19
+ ## Using Clearance
20
+
21
+ [Clearance][clearance] provides Rails authentication with email & password.
22
+
23
+ ```ruby
24
+ class Admin::ApplicationController < Administrate::ApplicationController
25
+ include Clearance::Controller
26
+ before_action :require_login
27
+ end
28
+ ```
29
+
30
+ ## Using Devise
31
+
32
+ [Devise][devise] is an authentication solution for Rails with Warden. Include
33
+ the authentication method for your model as a `before_action`:
34
+
35
+ ```ruby
36
+ class Admin::ApplicationController < Administrate::ApplicationController
37
+ before_action :authenticate_user!
38
+ end
39
+ ```
40
+
41
+ ## Using HTTP Basic authentication
42
+
43
+ Rails includes the [`http_basic_authenticate_with`][rails-http-basic-auth]
44
+ method which can be added to your base admin controller:
45
+
46
+ ```ruby
47
+ class Admin::ApplicationController < Administrate::ApplicationController
48
+ http_basic_authenticate_with(
49
+ name: ENV.fetch("ADMIN_NAME"),
50
+ password: ENV.fetch("ADMIN_PASSWORD")
51
+ )
52
+ end
53
+ ```
54
+
55
+ With this approach consider using [dotenv][dotenv] to setup your environment and
56
+ avoid committing secrets in your repository.
57
+
58
+ [clearance]: https://github.com/thoughtbot/clearance
59
+ [devise]: https://github.com/plataformatec/devise
60
+ [rails-http-basic-auth]: http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html
61
+ [dotenv]: https://github.com/bkeepers/dotenv
@@ -0,0 +1,53 @@
1
+ # Customizing attribute partials
2
+
3
+ Occasionally you might want to change how specific types of attributes appear
4
+ across all dashboards. You can customize the following built in field types:
5
+
6
+ - `belongs_to`
7
+ - `boolean`
8
+ - `date_time`
9
+ - `email`
10
+ - `has_many`
11
+ - `has_one`
12
+ - `number`
13
+ - `polymporphic`
14
+ - `select`
15
+ - `string`
16
+ - `text`
17
+
18
+ For example, you might want all `Number` values to round to three decimal points.
19
+
20
+ To get started, run the appropriate rails generator:
21
+
22
+ ```bash
23
+ rails generate administrate:views:field number
24
+ ```
25
+
26
+ This will generate three files:
27
+
28
+ - `app/view/fields/number/_form.html.erb`
29
+ - `app/view/fields/number/_index.html.erb`
30
+ - `app/view/fields/number/_show.html.erb`
31
+
32
+ You can generate the partials for all field types by passing `all` to the generator.
33
+
34
+ ```bash
35
+ rails generate administrate:views:field all
36
+ ```
37
+
38
+ The generated templates will have documentation
39
+ describing which variables are in scope.
40
+ The rendering part of the partial will look like:
41
+
42
+ ```eruby
43
+ <%= field.data %>
44
+ ```
45
+
46
+ Changing numbers to display to three decimal places might look like this:
47
+
48
+ ```eruby
49
+ <%= field.data.round(3) %>
50
+ ```
51
+
52
+ If you only want to change how an attribute appears
53
+ on a single page (e.g. `index`), you may delete the unnecessary templates.
@@ -0,0 +1,42 @@
1
+ # Customizing controller actions
2
+
3
+ When you install Administrate into your app,
4
+ we generate empty controllers for each of your resources.
5
+ If you want to create more complex application behavior for a dashboard,
6
+ you can overwrite controller actions.
7
+
8
+ The generated controller will look something like:
9
+
10
+ ```ruby
11
+ # app/controllers/admin/foos_controller.rb
12
+
13
+ class Admin::FoosController < Admin::ApplicationController
14
+
15
+ # Overwrite any of the RESTful controller actions to implement custom behavior
16
+ # For example, you may want to send an email after a foo is updated.
17
+ #
18
+ # def update
19
+ # foo = Foo.find(params[:id])
20
+ # foo.update(params[:foo])
21
+ # send_foo_updated_email
22
+ # end
23
+
24
+ # Override this method to specify custom lookup behavior.
25
+ # This will be used to set the resource for the `show`, `edit`, and `update`
26
+ # actions.
27
+ #
28
+ # def find_resource(param)
29
+ # Foo.find_by!(slug: param)
30
+ # end
31
+ #
32
+ # Override this if you have certain roles that require a subset
33
+ # this will be used to set the records shown on the `index` action.
34
+ # def scoped_resource
35
+ # if current_user.super_admin?
36
+ # resource_class
37
+ # else
38
+ # resource_class.with_less_stuff
39
+ # end
40
+ # end
41
+ end
42
+ ```
@@ -0,0 +1,202 @@
1
+ # Customizing Dashboards
2
+
3
+ In order to customize which attributes get displayed for each resource,
4
+ edit the dashboard file generated by the installation generator.
5
+
6
+ By default, the file will look something like this:
7
+
8
+ ```ruby
9
+ require "administrate/dashboard/base"
10
+
11
+ class CustomerDashboard < Administrate::Dashboard::Base
12
+ ATTRIBUTE_TYPES = {
13
+ id: Field::Integer,
14
+ name: Field::String,
15
+ email: Field::String,
16
+ created_at: Field::DateTime,
17
+ updated_at: Field::DateTime,
18
+ orders: Field::HasMany,
19
+ }
20
+
21
+ COLLECTION_ATTRIBUTES = [
22
+ :id,
23
+ :name,
24
+ :email,
25
+ :created_at,
26
+ :updated_at,
27
+ :orders,
28
+ ]
29
+
30
+ SHOW_PAGE_ATTRIBUTES = [
31
+ :id,
32
+ :name,
33
+ :email,
34
+ :created_at,
35
+ :updated_at,
36
+ :orders,
37
+ ]
38
+
39
+ FORM_ATTRIBUTES = [
40
+ :name,
41
+ :email,
42
+ :orders,
43
+ ]
44
+ end
45
+ ```
46
+
47
+ To change which attributes appear on each of the `index`, `show`, and `edit`
48
+ pages, add or remove attributes to each constant array.
49
+
50
+ Finally, the `ATTRIBUTE_TYPES` method defines how each attribute is displayed
51
+ throughout the dashboard. There are a number of `Field` classes that you can
52
+ specify, including:
53
+
54
+ - `Field::BelongsTo`
55
+ - `Field::Boolean`
56
+ - `Field::DateTime`
57
+ - `Field::Email`
58
+ - `Field::HasMany`
59
+ - `Field::HasOne`
60
+ - `Field::Number`
61
+ - `Field::Polymorphic`
62
+ - `Field::Select`
63
+ - `Field::String`
64
+ - `Field::Text`
65
+
66
+ ## Customizing Fields
67
+
68
+ ### Setting Options
69
+
70
+ Each of the `Field` types take a different set of options,
71
+ which are specified through the `.with_options` class method:
72
+
73
+ **Field::BelongsTo**
74
+
75
+ `:order` - order of the dropdown menu, can be ordered by more than one column `"name, email DESC"`
76
+
77
+ **Field::HasMany**
78
+
79
+ `:limit` - Set the number of resources to display in the show view. Default is
80
+ `5`.
81
+
82
+ `:sort_by` - What to sort the association by in the show view.
83
+
84
+ `:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.
85
+
86
+ `:primary_key` - Specifies object's primary_key. Defaults to `:id`.
87
+
88
+ `:foreign_key` - Specifies the name of the foreign key directly. Defaults to `:#{attribute}_id`
89
+
90
+ **Field::BelongsTo**
91
+
92
+ `:primary_key` - Specifies object's primary_key. Defaults to `:id`.
93
+
94
+ `:foreign_key` - Specifies the name of the foreign key directly. Defaults to `:#{attribute}_id`
95
+
96
+ **Field::Number**
97
+
98
+ `:decimals` - Set the number of decimals to display. Defaults to `0`.
99
+
100
+ `:prefix` - Prefixes the number with a string. Defaults to `""`.
101
+
102
+ `:suffix` - Suffixes the number with a string. Defaults to `""`.
103
+
104
+ For example, you might use the following to display U.S. currency:
105
+
106
+ ```ruby
107
+ unit_price: Field::Number.with_options(
108
+ prefix: "$",
109
+ decimals: 2,
110
+ )
111
+ ```
112
+
113
+ Or, to display a distance in kilometers:
114
+
115
+ ```ruby
116
+ unit_price: Field::Number.with_options(
117
+ suffix: " km",
118
+ decimals: 2,
119
+ )
120
+ ```
121
+
122
+ **Field::Polymorphic**
123
+
124
+ `:classes` - Specify a list of classes whose objects will be used to populate select boxes for editing this polymorphic field.
125
+ Default is `[]`.
126
+
127
+ **Field::Select**
128
+
129
+ `:collection` - Specify the array or range to select from. Defaults to `[]`.
130
+
131
+ `:searchable` - Specify if the attribute should be considered when searching.
132
+ Default is `true`.
133
+
134
+ **Field::String**
135
+
136
+ `:searchable` - Specify if the attribute should be considered when searching.
137
+ Default is `true`.
138
+
139
+ `:truncate` - Set the number of characters to display in the index view.
140
+ Defaults to `50`.
141
+
142
+ **Field::Text**
143
+
144
+ `:searchable` - Specify if the attribute should be considered when searching.
145
+ Default is `false`.
146
+
147
+ `:truncate` - Set the number of characters to display in the index view.
148
+ Defaults to `50`.
149
+
150
+ ### Defining Labels
151
+
152
+ To change the user-facing label for an attribute,
153
+ define a custom I18n translation:
154
+
155
+ ```yaml
156
+ en:
157
+ helpers:
158
+ label:
159
+ customer:
160
+ name: Full Name
161
+ ```
162
+
163
+
164
+ To change the labels used for resources in dashboard collections.
165
+ Assume you have a users dashboard and you want to change "User #1" to "Testy
166
+ McTesterson", the user's name.
167
+
168
+ Add this method to the dashboard for Users.
169
+ Use whatever attribute or method you like.
170
+ Example for *user*:
171
+
172
+ ````ruby
173
+ def display_resource(user)
174
+ user.name
175
+ end
176
+ ````
177
+
178
+ [define your own]: /adding_custom_field_types
179
+
180
+ To change the dashboard name in sidebar menu, sub-header and search string use default ActiveRecord i18n translations for models:
181
+
182
+ ```yaml
183
+ en:
184
+ activerecord:
185
+ models:
186
+ customer:
187
+ one: Happy Customer
188
+ others: Happy Customers
189
+ ```
190
+
191
+ ## Customizing Actions
192
+
193
+ To enable or disable certain actions you could override `valid_action?` method in your dashboard controller like this:
194
+
195
+ ```ruby
196
+ # disable 'edit' and 'destroy' links
197
+ def valid_action?(name, resource = resource_class)
198
+ %w[edit destroy].exclude?(name.to_s) && super
199
+ end
200
+ ```
201
+
202
+ Action is one of `new`, `edit`, `show`, `destroy`.