Fields are the backbone of a
Resource. Through fields you tell Avo what to fetch from the database and how to display it on the
Avo ships with various simple fields like
select, and more complex ones like
You add fields to a resource through the
fields method using the
field DATABASE_COLUMN, as: FIELD_TYPE, **FIELD_OPTIONS notation.
def fields field :name, as: :text end
name property is the column in the database where Avo looks for information or a property on your model.
That will add a few fields in your new Avo app.
Show views, we'll get a new text column of that record's database value. Finally, on the
New views, we will get a text input field that will display & update the
name field on that model.
When we declare a field, we pinpoint the specific database row for that field. Usually, that's a snake case value.
Each field has a label. Avo will convert the snake case name to a humanized version. In the following example, the
is_available field will render the label as Is available.
field :is_available, as: :boolean
If having the fields stacked one on top of another is not the right layout, try the resource-sidebar.
A more complex example
class Avo::Resources::User < Avo::BaseResource def fields field :id, as: :id field :first_name, as: :text field :last_name, as: :text field :email, as: :text field :active, as: :boolean field :cv, as: :file field :is_admin?, as: :boolean end end
fields method is already hydrated with the
context variables so you can use them to conditionally show/hide fields
class Avo::Resources::User < Avo::BaseResource def fields field :id, as: :id field :first_name, as: :text field :last_name, as: :text field :email, as: :text field :is_admin?, as: :boolean field :active, as: :boolean if current_user.is_admin? field :cv, as: :file end end end