Class: Railspress::Admin::CategoriesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/railspress/admin/categories_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
# File 'app/controllers/railspress/admin/categories_controller.rb', line 14

def create
  @category = Category.new(category_params)
  if @category.save
    redirect_to admin_categories_path, notice: "Category created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



34
35
36
37
38
39
40
# File 'app/controllers/railspress/admin/categories_controller.rb', line 34

def destroy
  if @category.destroy
    redirect_to admin_categories_path, notice: "Category deleted."
  else
    redirect_to admin_categories_path, alert: "Cannot delete category with posts."
  end
end

#editObject



23
24
# File 'app/controllers/railspress/admin/categories_controller.rb', line 23

def edit
end

#indexObject



6
7
8
# File 'app/controllers/railspress/admin/categories_controller.rb', line 6

def index
  @categories = Category.ordered
end

#newObject



10
11
12
# File 'app/controllers/railspress/admin/categories_controller.rb', line 10

def new
  @category = Category.new
end

#updateObject



26
27
28
29
30
31
32
# File 'app/controllers/railspress/admin/categories_controller.rb', line 26

def update
  if @category.update(category_params)
    redirect_to admin_categories_path, notice: "Category updated."
  else
    render :edit, status: :unprocessable_entity
  end
end