vereto-api/app/controllers/articles_controller.rb
2018-02-19 16:03:07 +00:00

46 lines
851 B
Ruby

class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :update, :destroy]
skip_before_action :authorize_request, only: [:index, :show]
# GET /articles
def index
@article = Article.all.to_json(include: :user)
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)
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])
end
end