Skip to content

Commit

Permalink
add movie resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Feb 18, 2025
1 parent 09a369f commit 707bbb7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/avo/resources/movie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Avo::Resources::Movie < Avo::Resources::ArrayResource
def records
[
{
id: 1,
name: "The Shawshank Redemption",
release_date: "1994-09-23"
},
{
id: 2,
name: "The Godfather",
release_date: "1972-03-24",
fun_fact: "The iconic cat in the opening scene was a stray found by director Francis Ford Coppola on the studio lot."
},
{
id: 3,
name: "Pulp Fiction",
release_date: "1994-10-14"
}
]
end

def fields
main_panel do
field :id, as: :id
field :name, as: :text
field :release_date, as: :date
field :fun_fact, only_on: :index, visible: -> { resource.record.fun_fact.present? } do
record.fun_fact.truncate_words(10)
end

sidebar do
field :fun_fact do
record.fun_fact || "There is no register of a fun fact for #{record.name}"
end
end
end
end
end
4 changes: 4 additions & 0 deletions app/controllers/avo/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/3.0/controllers.html
class Avo::MoviesController < Avo::ArrayController
end
1 change: 1 addition & 0 deletions config/initializers/avo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@

group "Other", collapsable: true, collapsed: true do
resource :fish, label: "Fishies"
resource :movie
end
end

Expand Down

0 comments on commit 707bbb7

Please sign in to comment.