Avo effortlessly empowers you to build a full admin dashboard for your Ruby on Rails application. One of the most powerful features is how easy you can administer your database records. Avo does this using Resources. Each resource maps out one of your models.
# Defining Resources
bin/rails generate avo:resource post
This command will generate a resource file under your
app/avo/resources directory. The
app/avo directory will hold all of your Avo configuration files.
Inside the creates resource file will look like so:
class PostResource < Avo::BaseResource self.title = :id self.includes =  field :id, as: :id # add fields here end
From this config, Avo will infer that the resource's model will be the
# Setting the title of the resource
title attribute is set to
:id, so the model's
id attribute will be used to display the resource in search results and belongs select fields. You usually change it to something more representative, like the model's
class PostResource < Avo::BaseResource self.title = :name # it will now reference @project.name to show you the title end
# Eager loading
If you regularly need access to a resource's associations, you can tell Avo to eager load those associations on the Index view using
includes. This will help you avoid those nasty
n+1 performance issues.
class PostResource < Avo::BaseResource self.includes = [:user, :tags] end
Each generated resource will have four views Index view where you see all your resources listed, Show view where you get to see one resource in more detail, Edit view where you can edit one resource and Create view where you can create a new resource.
# Grid view
On Index view, the most common view type is
:table. You might have some data that you want to display in a grid view. You change that by setting
:grid and add the
class PostResource < Avo::BaseResource self.default_view_type = :grid end
See how you can customize the grid item in the additional grid view documentation.
# Devise password optional
If you use
devise and you update your user models (usually
User) without passing a password you will get a validation error. You can use
devise_password_optional to stop receiving that error. It will strip out (opens new window) the
password key from
class UserResource < Avo::BaseResource self.devise_password_optional = true end
It's a very common scenario to add filters to your resources to make it easier to find your records. Check out the additional Filters documentation to see how easy it is to set up custom filters with Avo.
Most of the time, you will want to trigger some events against your records or run more heavy updates. Avo makes this so easy with Actions.
Check out the additional Actions documentation.