Class: Katalyst::Navigation::ItemsController

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/katalyst/navigation/items_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#editorObject (readonly)

Returns the value of attribute editor.



9
10
11
# File 'app/controllers/katalyst/navigation/items_controller.rb', line 9

def editor
  @editor
end

#itemObject (readonly)

Returns the value of attribute item.



9
10
11
# File 'app/controllers/katalyst/navigation/items_controller.rb', line 9

def item
  @item
end

Returns the value of attribute menu.



9
10
11
# File 'app/controllers/katalyst/navigation/items_controller.rb', line 9

def menu
  @menu
end

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/katalyst/navigation/items_controller.rb', line 22

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
end

#editObject



18
19
20
# File 'app/controllers/katalyst/navigation/items_controller.rb', line 18

def edit
  render_editor
end

#newObject



11
12
13
14
15
16
# File 'app/controllers/katalyst/navigation/items_controller.rb', line 11

def new
  @item   = @menu.items.build(new_item_params)
  @editor = Katalyst::Navigation::EditorComponent.new(menu:, item:)

  render_editor
end

#updateObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/katalyst/navigation/items_controller.rb', line 33

def update
  @item.attributes = item_params

  if @item.valid?
    previous = @item
    @item    = @item.dup.tap(&:save!)

    render locals: { editor:, item:, previous: }
  else
    render_editor status: :unprocessable_entity
  end
end