-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathavo.mdc
37 lines (25 loc) · 1.53 KB
/
avo.mdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
description: Descriptor
globs:
alwaysApply: true
---
# Resources
The Avo CRUD functionality uses the concept of a resource. A resource belongs to a model and a model may have multiple resources.
The model is how Rails talks to the database and the resource is how Avo talks to Rails and knows how to fetch and manipulate the records.
Each resource is a class defined in a file. They inherit the `Avo::BaseResource` class which inherits `Avo::Resources::Base`. `Avo::BaseResource` is empty so the user can override anything they want on a global level in theyr own app.
A resource has a multitude of options which are usually declared using the `self.OPTION_NAME = ` format. They can take a simple value like a string, boolean, symbol, hash or array or they can take an `ExecutionContext` which will give the developer much more control over what they can return from it.
## Fields
Fields are declared using the `field` method inside a `fields` method in a resource like so:
```ruby
class Avo::Resources::Team < Avo::BaseResource
def fields
field :id, as: :id
field :name, as: :text
field :description, as: :textarea
end
end
```
All fields have a name which is the first argument and the type of the field, as the `as:` argument.
Most fields support optons that are universal for all fields. Some examples are: readonly, disabled, help, format_using, update using, hide_on, show_on, and others.
Some fields have their own proprietary options, like `rows` for `textarea` fields and `options` for `select` fields.
All field options: