Class: OCms::CategoriesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/o_cms/categories_controller.rb', line 18

def create
  @category = Category.new(category_params)

  if @category.save
    flash[:notice] = "Category was saved successfully."
    redirect_to edit_category_path(@category)
  else
    flash.now[:alert] = "Error creating category. Please try again."
    render :new
  end
end

#destroyObject



47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/o_cms/categories_controller.rb', line 47

def destroy
  @category = Category.find(params[:id])

  if @category.destroy
    flash[:notice] = "\"#{@category.name}\" was deleted successfully."
    redirect_to action: :index
  else
    flash.now[:alert] = "There was an error deleting the category."
    render :show
  end
end

#editObject



30
31
32
# File 'app/controllers/o_cms/categories_controller.rb', line 30

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

#indexObject



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

def index
  @categorys = Category.all
end

#newObject



14
15
16
# File 'app/controllers/o_cms/categories_controller.rb', line 14

def new
  @category = Category.new
end

#showObject



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

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

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/o_cms/categories_controller.rb', line 34

def update
  @category = Category.find(params[:id])
  @category.assign_attributes(category_params)

  if @category.save
    flash[:notice] = "Category was updated successfully."
    redirect_to edit_category_path(@category)
  else
    flash.now[:alert] = "Error saving category. Please try again."
    render :edit
  end
end