Sha256: 8fa25e7401f8658a688aa6baad93251d74d37ea252f03757bb1b66c9c6362bf2

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module  Crowdblog
  class PostsController < ApplicationController
    respond_to :html, :json
    cache_sweeper :post_sweeper

    def index
      @posts = Post.scoped_for(current_user).all_posts_json
      respond_to do |format|
        format.json { render json: @posts }
        format.html
      end
    end

    def create
      @post = Post.new(params[:post])
      @post.author = current_user
      @post.regenerate_permalink
      @post.save
      respond_with @post
    end

    def destroy
      @post = Post.scoped_for(current_user).find(params[:id])
      @post.destroy
      respond_with @post
    end

    def show
      @post = Post.includes(:assets).find(params[:id])
      respond_to do |format|
        format.json { render json: @post.to_json(include: :assets) }
      end
    end

    def update
      @post = Post.scoped_for(current_user).find(params[:id])
      @post.update_attributes(params[:post], updated_by: current_user)
      if @post.allowed_to_update_permalink?
        @post.regenerate_permalink
        @post.save!
      end

      @post.publish_if_allowed(params[:transition], current_user) if params[:transition]

      respond_with @post
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crowdblog-0.0.2 app/controllers/crowdblog/posts_controller.rb
crowdblog-0.0.1 app/controllers/crowdblog/posts_controller.rb