Class: Blog::ArticlesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Blog::ArticlesController
- Defined in:
- app/controllers/blog/articles_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /articles.
-
#destroy ⇒ Object
DELETE /articles/1.
-
#index ⇒ Object
GET /articles.
-
#show ⇒ Object
GET /articles/1.
-
#update ⇒ Object
PATCH/PUT /articles/1.
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#index ⇒ Object
GET /articles
6 7 8 |
# File 'app/controllers/blog/articles_controller.rb', line 6 def index render json: Article.filters(params) end |
#show ⇒ Object
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 |
#update ⇒ Object
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 |