Sha256: 7f31cb9753dbe34cae90189c89be5829dd19c90a2a675869b1b52cc7a7023c6b
Contents?: true
Size: 1.84 KB
Versions: 3
Compression:
Stored size: 1.84 KB
Contents
require_dependency "notee/application_controller" module Notee class PostsController < ApplicationController # callbacks before_action :set_post, only: [:show, :update, :destroy] skip_before_action :restrict_access_json, only: [:notee] before_action :restrict_access, only: [:notee] def notee end # GET /posts def index @posts = Post.all render json: { status: 'success', posts: @posts} end # GET /posts/1 def show render json: { status: 'success', post: @post} end # POST /posts def create @post = Post.new(post_params) respond_to do |format| if @post.save format.json { render json: @post, status: 200 } else format.json { render json: @post.errors, status: :unprocessable_entity } end end end # PATCH/PUT /posts/1 def update respond_to do |format| if @post.update(post_params) format.json { render json: @post, status: 200 } else format.json { render json: @post.errors, status: :unprocessable_entity } end end end # DELETE /posts/1 def destroy @post.destroy render json: { status: 'success'} end private def set_post @post = Post.find_by(id: params[:id]) end # Only allow a trusted parameter "white list" through. def post_params params.require(:post).permit(:title, :content, :slug, :status, :category_id, :thumbnail_id, :published_at, :seo_keyword, :seo_description) end def restrict_access # authenticate_or_request_with_http_token do |token, options| # Token.exists?(access_token: token) # end unless Token.exists?(access_token: session[:access_token]) redirect_to new_token_path and return end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
notee-0.3.1 | app/controllers/notee/posts_controller.rb |
notee-0.3.0 | app/controllers/notee/posts_controller.rb |
notee-0.2.9 | app/controllers/notee/posts_controller.rb |