Use polymorphic routes to manage cards

We use a different logic to load the card depending on the controller
we're using, and then share the rest of the code. This way we simplify
the code a bit, since we don't have to check for the page_id parameter.
This commit is contained in:
Javi Martín
2021-01-06 20:09:36 +01:00
parent 04e817e696
commit 4c0bb894eb
12 changed files with 99 additions and 79 deletions

View File

@@ -227,7 +227,7 @@ namespace :admin do
namespace :site_customization do
resources :pages, except: [:show] do
resources :cards, only: [:index]
resources :cards, except: [:show], as: :widget_cards
end
resources :images, only: [:index, :update, :destroy]
resources :content_blocks, except: [:show]
@@ -270,6 +270,10 @@ resolve "Audit" do |audit|
[*resource_hierarchy_for(audit.associated || audit.auditable), audit]
end
resolve "Widget::Card" do |card, options|
[*resource_hierarchy_for(card.page), card]
end
resolve "Budget::Group" do |group, options|
[group.budget, :group, options.merge(id: group)]
end