Skip to content

Instantly share code, notes, and snippets.

@davidlormor
Last active April 2, 2024 16:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidlormor/d1d7e32a3568f6a9b3540669e7f601dc to your computer and use it in GitHub Desktop.
Save davidlormor/d1d7e32a3568f6a9b3540669e7f601dc to your computer and use it in GitHub Desktop.
Avo resource view helpers
# frozen_string_literal: true
class ExampleResource < Avo::BaseResource
include ResourceExtensions
field :id, as: :id
field :name, as: :text
index do
field :some_field, as: :text
field :some_index_field, as: :text, sortable: true
end
show do
field :some_show_field, as: :markdown
field :some_field, as: :text
end
create do
field :some_create_field, as: :number
end
edit do
field :some_create_field, as: :number, readonly: true
field :some_field
field :some_editable_field, as: :text
end
end
# frozen_string_literal: true
require "active_support/concern"
module ResourceExtensions
extend ActiveSupport::Concern
class_methods do
def index(&block)
with_options only_on: :index, &block
end
def show(&block)
with_options only_on: :show, &block
end
def create(&block)
with_options only_on: :new, &block
end
def edit(&block)
with_options only_on: :edit, &block
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment