Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of how to use a custom field #508

Merged
merged 1 commit into from
Mar 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions docs/adding_custom_field_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,24 @@ Since we want to display an image, we can change it to:
You can customize the other generated partials in the same way
for custom behavior on the index and form pages.

To use your custom field types, change the type of an attribute in one of the Dashboard-Files (e.g. `app/dashboard/user_dashboard.rb`) to your new field type:
## Using your custom field

```eruby
ATTRIBUTE_TYPES = {
id: Field::Number,
name: Field::String,
created_at: Field::DateTime,
updated_at: Field::DateTime,
gravatar: GravatarField
}
We need to tell Administrate which attributes we'd like to be displayed as a
gravatar image.

Open up a dashboard file, and add the gravatar field into the `ATTRIBUTE_TYPES`
hash. It should look something like:

```ruby
class UserDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
created_at: Field::DateTime,
updated_at: Field::DateTime,
name: Field::String,
email: GravatarField, # Update this email to use your new field class
# ...
}
end
```

[Customizing Attribute Partials]: /customizing_attribute_partials