<commit_before>---
title: Customizing Dashboards
---

In order to customize which attributes get displayed for each resource,
edit the dashboard file generated by the installation generator.

By default, the file will look something like this:

```ruby
require "administrate/base_dashboard"

class CustomerDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    id: Field::Number,
    name: Field::String,
    email: Field::String,
    created_at: Field::DateTime,
    updated_at: Field::DateTime,
    orders: Field::HasMany,
  }

  COLLECTION_ATTRIBUTES = [
    :id,
    :name,
    :email,
    :created_at,
    :updated_at,
    :orders,
  ]

  SHOW_PAGE_ATTRIBUTES = [
    :id,
    :name,
    :email,
    :created_at,
    :updated_at,
    :orders,
  ]

  FORM_ATTRIBUTES = [
    :name,
    :email,
    :orders,
  ]
end
```

To change which attributes appear on each of the `index`, `show`, and `edit`
pages, add or remove attributes to each constant array.

Finally, the `ATTRIBUTE_TYPES` method defines how each attribute is displayed
throughout the dashboard. There are a number of `Field` classes that you can
specify, including:

- `Field::BelongsTo`
- `Field::Boolean`
- `Field::DateTime`
- `Field::Date`
- `Field::Email`
- `Field::HasMany`
- `Field::HasOne`
- `Field::Number`
- `Field::Polymorphic`
- `Field::Select`
- `Field::String`
- `Field::Text`
- `Field::Url`
- `Field::Password`

## Customizing Fields

### Setting Options

Each of the `Field` types take a different set of options,
which are specified through the `.with_options` class method:

**Field::BelongsTo**

`:order` - Specifies the column used to order the records. It will apply both in
the table views and in the dropdown menu on the record forms.
You can set multiple columns as well with direction. E.g.: `"name, email DESC"`.

`:scope` - Specifies a custom scope inside a callable. Useful for preloading.
Example: `.with_options(scope: -> { MyModel.includes(:rel).limit(5) })`

`:include_blank` - Specifies if the select element to be rendered should include
blank option. Default is `true`.

`:searchable` - Specify if the attribute should be considered when searching.
Default is `false`.

`searchable_fields` - Specify which columns to use on the search, only applies
if `searchable` is `true`

For example:

```ruby
  country: Field::BelongsTo.with_options(
    searchable: true,
    searchable_fields: ['name'],
  )
```

with this, you will be able to search through the column `name` from the
association `belongs_to :country`, from your model.

`:primary_key` (deprecated) - Specifies the association's primary_key.

`:foreign_key` (deprecated) - Specifies the name of the foreign key directly.

`:class_name` (deprecated) - Specifies the name of the associated class.

**Field::HasMany**

`:limit` - Set the number of resources to display in the show view. If not want 
use paginate in show page, you can set as `0` or `false`. Default is `5`.

`:sort_by` - What to sort the association by in the show view.

`:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.

`:primary_key` (deprecated) - Specifies object's primary_key.

`:foreign_key` (deprecated) - Specifies the name of the foreign key directly.

`:class_name` (deprecated) - Specifies the name of the associated class.

**Field::HasOne**

`:searchable` - Specify if the attribute should be considered when searching.
Default is `false`.

`searchable_fields` - Specify which columns to use on the search, only applies if
`searchable` is `true`

For example:

```ruby
  cities: Field::HasMany.with_options(
    searchable: true,
    searchable_fields: ['name'],
  )
```
<commit_msg>Update document of paginated for has_many<commit_after>---
title: Customizing Dashboards
---

In order to customize which attributes get displayed for each resource,
edit the dashboard file generated by the installation generator.

By default, the file will look something like this:

```ruby
require "administrate/base_dashboard"

class CustomerDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    id: Field::Number,
    name: Field::String,
    email: Field::String,
    created_at: Field::DateTime,
    updated_at: Field::DateTime,
    orders: Field::HasMany,
  }

  COLLECTION_ATTRIBUTES = [
    :id,
    :name,
    :email,
    :created_at,
    :updated_at,
    :orders,
  ]

  SHOW_PAGE_ATTRIBUTES = [
    :id,
    :name,
    :email,
    :created_at,
    :updated_at,
    :orders,
  ]

  FORM_ATTRIBUTES = [
    :name,
    :email,
    :orders,
  ]
end
```

To change which attributes appear on each of the `index`, `show`, and `edit`
pages, add or remove attributes to each constant array.

Finally, the `ATTRIBUTE_TYPES` method defines how each attribute is displayed
throughout the dashboard. There are a number of `Field` classes that you can
specify, including:

- `Field::BelongsTo`
- `Field::Boolean`
- `Field::DateTime`
- `Field::Date`
- `Field::Email`
- `Field::HasMany`
- `Field::HasOne`
- `Field::Number`
- `Field::Polymorphic`
- `Field::Select`
- `Field::String`
- `Field::Text`
- `Field::Url`
- `Field::Password`

## Customizing Fields

### Setting Options

Each of the `Field` types take a different set of options,
which are specified through the `.with_options` class method:

**Field::BelongsTo**

`:order` - Specifies the column used to order the records. It will apply both in
the table views and in the dropdown menu on the record forms.
You can set multiple columns as well with direction. E.g.: `"name, email DESC"`.

`:scope` - Specifies a custom scope inside a callable. Useful for preloading.
Example: `.with_options(scope: -> { MyModel.includes(:rel).limit(5) })`

`:include_blank` - Specifies if the select element to be rendered should include
blank option. Default is `true`.

`:searchable` - Specify if the attribute should be considered when searching.
Default is `false`.

`searchable_fields` - Specify which columns to use on the search, only applies
if `searchable` is `true`

For example:

```ruby
  country: Field::BelongsTo.with_options(
    searchable: true,
    searchable_fields: ['name'],
  )
```

with this, you will be able to search through the column `name` from the
association `belongs_to :country`, from your model.

`:primary_key` (deprecated) - Specifies the association's primary_key.

`:foreign_key` (deprecated) - Specifies the name of the foreign key directly.

`:class_name` (deprecated) - Specifies the name of the associated class.

**Field::HasMany**

`:limit` - The number of resources (paginated) to display in the show view. To disable pagination,
set this to `0` or `false`. Default is `5`.

`:sort_by` - What to sort the association by in the show view.

`:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.

`:primary_key` (deprecated) - Specifies object's primary_key.

`:foreign_key` (deprecated) - Specifies the name of the foreign key directly.

`:class_name` (deprecated) - Specifies the name of the associated class.

**Field::HasOne**

`:searchable` - Specify if the attribute should be considered when searching.
Default is `false`.

`searchable_fields` - Specify which columns to use on the search, only applies if
`searchable` is `true`

For example:

```ruby
  cities: Field::HasMany.with_options(
    searchable: true,
    searchable_fields: ['name'],
  )
```

{'fraction_non_alphanumeric': 0.11377245508982035, 'fraction_numerical': 0.0008165487207403375, 'mean_word_length': 4.164441321152495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2243737', 'n_tokens_mistral': 2297, 'n_tokens_neox': 2242, 'n_words': 845}