Class: BlogBoi::ArticlesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/blog_boi/articles_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin

Instance Method Details

#category_indexObject

GET /articles/category/cool_category



61
62
63
64
65
# File 'app/controllers/blog_boi/articles_controller.rb', line 61

def category_index
	@articles = Article.with_category_name(params[:category_name]).where(hidden: false)
	@category_title = params[:category_name].titleize
	render :index
end

#createObject

POST /articles



35
36
37
38
39
40
41
42
43
# File 'app/controllers/blog_boi/articles_controller.rb', line 35

def create
  @article = Article.new(article_params)

  if @article.save
    redirect_to article_path(@article.slug), notice: 'Article was successfully created.'
  else
    render :new
  end
end

#destroyObject

DELETE /articles/1



55
56
57
58
# File 'app/controllers/blog_boi/articles_controller.rb', line 55

def destroy
  @article.destroy
  redirect_to articles_url, notice: 'Article was successfully destroyed.'
end

#editObject

GET /articles/1/edit



31
32
# File 'app/controllers/blog_boi/articles_controller.rb', line 31

def edit
end

#indexObject

GET /articles



11
12
13
14
# File 'app/controllers/blog_boi/articles_controller.rb', line 11

def index
  @articles = Article.all.where({hidden: false})
  @articles_hidden = Article.all.where({hidden: true})
end

#newObject

GET /articles/new



26
27
28
# File 'app/controllers/blog_boi/articles_controller.rb', line 26

def new
  @article = Article.new
end

#showObject

GET /articles/1



17
18
19
20
21
22
23
# File 'app/controllers/blog_boi/articles_controller.rb', line 17

def show
	@meta_tags = {
		title: @article.title,
		description: @article.description,
		image: @article.image.attached? ? main_app.url_for(@article.image) : nil,
	}
end

#updateObject

PATCH/PUT /articles/1



46
47
48
49
50
51
52
# File 'app/controllers/blog_boi/articles_controller.rb', line 46

def update
  if @article.update(article_params)
    redirect_to article_path(@article.slug), notice: 'Article was successfully updated.'
  else
    render :edit
  end
end