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



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

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



20
21
22
# File 'app/controllers/katalyst/navigation/items_controller.rb', line 20

def edit
  render_editor
end

#newObject



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

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

  render_editor
end

#updateObject



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

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