Class: SimpleShowcaseAdmin::CategoriesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#not_authenticated

Instance Method Details

#createObject



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

def create
  @category = SimpleShowcaseAdmin::Category.new(params[:category])
  if @category.save
    redirect_to [ @category], notice: 'Successfully created new category'
  else
    render :new
  end
end

#destroyObject



38
39
40
41
42
# File 'app/controllers/simple_showcase_admin/categories_controller.rb', line 38

def destroy
  @category = SimpleShowcaseAdmin::Category.find(params[:id])
  @category.destroy
  redirect_to categories_path
end

#editObject



11
12
13
# File 'app/controllers/simple_showcase_admin/categories_controller.rb', line 11

def edit
  @category = SimpleShowcaseAdmin::Category.find(params[:id])
end

#indexObject



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

def index
  @categories = SimpleShowcaseAdmin::Category.rank(:row_order).page(params[:page]).per(10)
end

#newObject



7
8
9
# File 'app/controllers/simple_showcase_admin/categories_controller.rb', line 7

def new
  @category = SimpleShowcaseAdmin::Category.new
end

#showObject



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

def show
  @category = SimpleShowcaseAdmin::Category.find(params[:id])
  @items = Item.where(category_id: @category.id).rank(:row_order).page(params[:page]).per(10)
end

#sortObject



44
45
46
47
48
49
50
# File 'app/controllers/simple_showcase_admin/categories_controller.rb', line 44

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

  render nothing: true
end

#updateObject



29
30
31
32
33
34
35
36
# File 'app/controllers/simple_showcase_admin/categories_controller.rb', line 29

def update
  @category = SimpleShowcaseAdmin::Category.find(params[:id])
  if @category.update_attributes(params[:category])
    redirect_to category_path(@category), notice: 'Successfully updated category'
  else
    render :edit
  end
end