Class: SimpleShowcaseAdmin::ItemsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#not_authenticated

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/simple_showcase_admin/items_controller.rb', line 20

def create
  @category = SimpleShowcaseAdmin::Category.find(params[:category_id])
  @item = @category.items.new(params[:item])
  if @item.save
    redirect_to category_item_path(@category, @item), notice: "Successful created #{@item.title.downcase}"
  else
    @photos = @item.photos.blank? ? @item.photos.new : @item.photos
    render :new
  end
end

#destroyObject



42
43
44
45
46
# File 'app/controllers/simple_showcase_admin/items_controller.rb', line 42

def destroy
  @item = SimpleShowcaseAdmin::Item.find(params[:id])
  @item.destroy
  redirect_to category_path(params[:category_id]), notice: "Successfully deleted #{@item.title}"
end

#editObject



8
9
10
11
12
# File 'app/controllers/simple_showcase_admin/items_controller.rb', line 8

def edit
  @item = SimpleShowcaseAdmin::Item.find(params[:id])
  @category = SimpleShowcaseAdmin::Category.find(params[:category_id])
  @photos = @item.photos.blank? ? @item.photos.new : @item.photos
end

#newObject



3
4
5
6
# File 'app/controllers/simple_showcase_admin/items_controller.rb', line 3

def new
  @item = SimpleShowcaseAdmin::Item.new
  @photos = @item.photos.new
end

#showObject



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

def show
  @item = SimpleShowcaseAdmin::Item.find(params[:id])
  @category = SimpleShowcaseAdmin::Category.find(params[:category_id])
  @photos = @item.photos
end

#sortObject



48
49
50
51
52
53
54
# File 'app/controllers/simple_showcase_admin/items_controller.rb', line 48

def sort
  @item = SimpleShowcaseAdmin::Item.find(params[:id])
  @item.row_order_position = params[:row_order_position]
  @item.save!

  render nothing: true
end

#updateObject



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/simple_showcase_admin/items_controller.rb', line 31

def update
  @category = SimpleShowcaseAdmin::Category.find(params[:category_id])
  @item = SimpleShowcaseAdmin::Item.find(params[:id])
  if @item.update_attributes!(params[:item])
    redirect_to category_item_path(@category, @item)
  else
    @photos = @item.photos.blank? ? @item.photos.new : @item.photos
    render :edit
  end
end