vereto-api/app/controllers/v1/articles_controller.rb

46 lines
862 B
Ruby
Raw Normal View History

2018-02-21 12:09:22 +00:00
class V1::ArticlesController < ApplicationController
2018-02-19 16:03:07 +00:00
before_action :set_article, only: [:show, :update, :destroy]
skip_before_action :authorize_request, only: [:index, :show]
# GET /articles
def index
2018-02-21 13:40:31 +00:00
@article = Article.all.reverse
2018-02-19 16:03:07 +00:00
json_response(@article)
end
# POST /articles
def create
@article = current_user.articles.create!(article_params)
json_response(@article, :created)
end
# GET /articles/:id
def show
json_response(@article.to_json(include: :user))
2018-02-19 16:03:07 +00:00
end
# PUT /articles/:id
def update
@article.update(article_params)
head :no_content
end
# DELETE /articles/:id
def destroy
@article.destroy
head :no_content
end
private
def article_params
# whitelist params
params.permit(:title, :post)
end
def set_article
@article = Article.find(params[:id])
2018-02-19 16:03:07 +00:00
end
end