Class: Blog::ArticlesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /articles



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

def create
  article = Article.new(article_params)

  if article.save
    render json: article, status: :created
  else
    render json: article.errors, status: :unprocessable_entity
  end
end

#destroyObject

DELETE /articles/1



37
38
39
40
# File 'app/controllers/blog/articles_controller.rb', line 37

def destroy
  @article.destroy
  render json: { success: true }
end

#indexObject

GET /articles



6
7
8
# File 'app/controllers/blog/articles_controller.rb', line 6

def index
  render json: Article.filters(params)
end

#showObject

GET /articles/1



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

def show
  @article.increment!(:view_count)
  render json: @article
end

#updateObject

PATCH/PUT /articles/1



28
29
30
31
32
33
34
# File 'app/controllers/blog/articles_controller.rb', line 28

def update
  if @article.update(article_params)
    render json: @article
  else
    render json: @article.errors, status: :unprocessable_entity
  end
end