What it does
avo-custom_controls
The row of buttons at the top of every record, Edit, Delete, Save, Back, is
the part of Avo your team clicks all day. By default Avo decides what sits
there. With Custom Controls, you make that call: define
show_controls,
edit_controls,
index_controls, or
row_controls on a resource and build each bar from
the pieces you want, in the order you want, across your
Show,
Edit,
Index,
and table-row views.
Compose the built-in buttons (back_button,
edit_button,
delete_button,
save_button) with your own
link_to links, Avo actions, and dropdown groups, set
each one's label, icon, style, and color, and wrap any of them in plain Ruby
conditionals so a control only shows when the record calls for it. It's a few
methods your agent writes on a control layer that's already built, and it
keeps working with every Avo release.
See it in action
What it looks like
Each bar is a block on the resource. Compose built-in buttons, your own
links, and Avo actions, and reach for
default_controls
when you only want to add to Avo's defaults rather than replace them.
Docs for each bar: Show, Edit, Index, and Row.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
# Show: built-ins plus a custom link and an action, shown conditionally
self.show_controls = -> do
back_button label: ""
link_to "View on site", post_path(record), target: :_blank
action Avo::Actions::Publish, style: :primary unless record.published?
delete_button
edit_button
end
# Edit: keep Avo's defaults, add one button of your own
self.edit_controls = -> do
link_to "Preview", preview_post_path(record), target: :_blank
default_controls
end
# Index: group links into a dropdown, then the create button
self.index_controls = -> do
list label: "Export", icon: "heroicons/outline/arrow-down-tray" do
link_to "CSV", export_posts_path(format: :csv)
action Avo::Actions::EmailReport
end
create_button label: "New post"
end
# Row: per-record buttons, hidden in grid view
self.row_controls = -> do
action Avo::Actions::Feature, label: "Feature", style: :primary unless params[:view_type] == "grid"
show_button
edit_button
delete_button
end
end
What you get
-
Separate control bars for Show, Edit, Index, and table-row views via
show_controls,edit_controls,index_controls, androw_controls -
Built-in buttons to compose:
back_button,edit_button,delete_button,save_button,create_button,detach_button, andattach_button -
Add your own
link_tolinks, trigger Avo actions, and group items into dropdown lists with dividers -
Per-control label, title, icon (Heroicons), style (
:primary,:outline,:text), and color - Plain Ruby conditionals to show or hide a control based on the record
-
default_controlsto drop Avo's standard buttons back in alongside your custom ones
Why it pays off
- Rearranging a control bar with a custom button takes a few lines in the resource this afternoon, not a custom view layer you spec and build over a sprint.
- Every Avo release makes it better: the control bars on Show, Edit, Index, and row views keep working through upgrades, with no overridden templates to re-patch.
- The DSL covers Show, Edit, Index, and row contexts across many apps, so it handles authorization and per-view differences a one-off override tends to skip.
- Your agent configures the same control DSL in every app, instead of generating a different override each time.