Last active
April 2, 2024 16:21
-
-
Save davidlormor/d1d7e32a3568f6a9b3540669e7f601dc to your computer and use it in GitHub Desktop.
Avo resource view helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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