Class: Postnhost::CategoriesController

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

Constant Summary collapse

PAGE_SIZE =
15

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @category = Postnhost::Category.new
  @category.assign_attributes(category_params)

  if @category.save
    redirect_to categories_url
  else
    render :new, status: :unprocessable_content
  end
end

#destroyObject



44
45
46
47
# File 'app/controllers/postnhost/categories_controller.rb', line 44

def destroy
  @category.destroy
  redirect_to categories_url, notice: "Category was successfully deleted."
end

#editObject



23
# File 'app/controllers/postnhost/categories_controller.rb', line 23

def edit; end

#indexObject



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

def index
  @categories = Postnhost::Category.order(updated_at: :desc)
end

#newObject



19
20
21
# File 'app/controllers/postnhost/categories_controller.rb', line 19

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

#showObject



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

def show
  articles = @category.articles.includes(:article_snapshot, :language).order(created_at: :desc)
  @pagy, @articles = pagy(:offset, articles, limit: PAGE_SIZE)
end

#updateObject



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

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