Class: Katalyst::Content::ItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/katalyst/content/items_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
# File 'app/controllers/katalyst/content/items_controller.rb', line 20

def create
  @item = item = @container.items.build(item_params)
  if item.save
    render :update, locals: { item: item, previous: @container.items.build(type: item.type) }
  else
    render :new, status: :unprocessable_entity, locals: { item: item }
  end
end

#editObject



16
17
18
# File 'app/controllers/katalyst/content/items_controller.rb', line 16

def edit
  render locals: { item: @item }
end

#newObject



12
13
14
# File 'app/controllers/katalyst/content/items_controller.rb', line 12

def new
  render locals: { item: @container.items.build(item_params) }
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/katalyst/content/items_controller.rb', line 29

def update
  @item.attributes = item_params

  if @item.valid?
    previous = @item
    @item    = @item.dup.tap(&:save!)
    render locals: { item: @item, previous: previous }
  else
    render :edit, status: :unprocessable_entity, locals: { item: @item }
  end
end