app/controllers/katalyst/navigation/items_controller.rb in katalyst-navigation-1.5.0 vs app/controllers/katalyst/navigation/items_controller.rb in katalyst-navigation-1.5.1
- old
+ new
@@ -1,26 +1,32 @@
# frozen_string_literal: true
module Katalyst
module Navigation
- class ItemsController < ApplicationController
+ class ItemsController < Katalyst::Navigation.config.base_controller.constantize
before_action :set_menu, only: %i[new create]
before_action :set_item, except: %i[new create]
attr_reader :menu, :item, :editor
layout nil
def new
+ @item = @menu.items.build(new_item_params)
+ @editor = Katalyst::Navigation::EditorComponent.new(menu:, item:)
+
render_editor
end
def edit
render_editor
end
def create
+ @item = @menu.items.build(item_params)
+ @editor = Katalyst::Navigation::EditorComponent.new(menu:, item:)
+
if item.save
render :update, locals: { editor:, item:, previous: @menu.items.build(type: item.type) }
else
render_editor status: :unprocessable_entity
end
@@ -58,11 +64,9 @@
params.require(:item).permit(item_params_type.permitted_params)
end
def set_menu
@menu = Menu.find(params[:menu_id])
- @item = @menu.items.build(item_params)
- @editor = Katalyst::Navigation::EditorComponent.new(menu:, item:)
end
def set_item
@item = Item.find(params[:id])
@menu = @item.menu