Class: Blogr::CategoriesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
# File 'app/controllers/blogr/categories_controller.rb', line 25

def create
  @category = Category.new(category_params)

  if @category.save
    redirect_to category_path(@category), notice: 'Category was successfully created.'
  else
    render action: 'new'
  end
end

#destroyObject



43
44
45
46
# File 'app/controllers/blogr/categories_controller.rb', line 43

def destroy
  @category.destroy
  redirect_to categories_url, notice: 'Category was successfully destroyed.'
end

#editObject



21
22
23
# File 'app/controllers/blogr/categories_controller.rb', line 21

def edit
  @title = "Editing '#{@category.title}'"
end

#indexObject



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

def index
  @categories = Category.all
  @title = "Categories"
end

#newObject



16
17
18
19
# File 'app/controllers/blogr/categories_controller.rb', line 16

def new
  @category = Category.new
  @title = "New Category"
end

#showObject



12
13
14
# File 'app/controllers/blogr/categories_controller.rb', line 12

def show
  @title = @category.title
end

#updateObject



35
36
37
38
39
40
41
# File 'app/controllers/blogr/categories_controller.rb', line 35

def update
  if @category.update(category_params)
    redirect_to category_path(@category), notice: 'Category was successfully updated.'
  else
    render action: 'edit'
  end
end