-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/better error for missing resource (#2062)
Co-authored-by: Adrian <[email protected]> Co-authored-by: Paul Bob <[email protected]>
- Loading branch information
1 parent
636d1c6
commit f4813ed
Showing
29 changed files
with
362 additions
and
65 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Avo::Resources::Event < Avo::BaseResource | ||
self.title = :name | ||
self.description = "An event that happened at a certain time." | ||
self.includes = [:location] | ||
|
||
def fields | ||
field :name, as: :text, link_to_record: true, sortable: true, stacked: true | ||
field :event_time, as: :datetime, sortable: true | ||
|
||
if params[:show_location_field] == '1' | ||
# Example for error message when resource is missing | ||
field :location, as: :belongs_to | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Avo::Resources::Store < Avo::BaseResource | ||
self.includes = [:location] | ||
|
||
def fields | ||
field :id, as: :id | ||
field :name, as: :text | ||
field :size, as: :text | ||
|
||
if params[:show_location_field] == '1' | ||
# Example for error message when resource is missing | ||
field :location, as: :has_one | ||
end | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Avo::EventsController < Avo::ResourcesController | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Avo::StoresController < Avo::ResourcesController | ||
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# == Schema Information | ||
# | ||
# Table name: locations | ||
# | ||
# id :bigint not null, primary key | ||
# team_id :bigint not null | ||
# name :text | ||
# address :string | ||
# size :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# store_id :bigint | ||
# | ||
class Location < ApplicationRecord | ||
belongs_to :store, optional: true | ||
belongs_to :team, optional: true | ||
|
||
has_and_belongs_to_many :courses, inverse_of: :locations | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# == Schema Information | ||
# | ||
# Table name: stores | ||
# | ||
# id :bigint not null, primary key | ||
# name :string | ||
# size :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class Store < ApplicationRecord | ||
has_one :location | ||
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateLocations < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :locations do |t| | ||
t.references :team, null: false, foreign_key: true | ||
t.text :name | ||
t.string :address | ||
t.string :size | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
spec/dummy/db/migrate/20231205153910_create_courses_locations.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateCoursesLocations < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :courses_locations do |t| | ||
t.references :user, null: false, foreign_key: true | ||
t.references :course, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
spec/dummy/db/migrate/20231206095919_add_location_to_events.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddLocationToEvents < ActiveRecord::Migration[6.1] | ||
def change | ||
add_reference :events, :location, null: true, foreign_key: true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateStores < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :stores do |t| | ||
t.string :name | ||
t.string :size | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
spec/dummy/db/migrate/20231206113153_add_store_to_locations.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddStoreToLocations < ActiveRecord::Migration[6.1] | ||
def change | ||
add_reference :locations, :store, foreign_key: true | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
spec/dummy/db/migrate/20231212231204_make_team_id_nullable_on_locations.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class MakeTeamIdNullableOnLocations < ActiveRecord::Migration[6.1] | ||
def change | ||
change_column :locations, :team_id, :bigint, null: true | ||
end | ||
end |
Oops, something went wrong.