Sha256: 3bed46eab8900b5587c47108de2e31f4293f30dfb4964bc59363254d53c5009f

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

module Storytime
  module Dashboard
    class BlogsController < PostsController
      respond_to :json

      def new
        @blog = current_post_type.new
        @blog.user = current_user
        authorize @blog
        respond_with @blog
      end

      def edit
        authorize @post
        @blog = @post
        respond_with @blog
      end

      def update
        authorize @post
        @blog = @post

        respond_with @blog do |format|
          if @blog.update_attributes(post_params)
            format.json { render :index }
          else
            format.json { render :edit, status: :unprocessable_entity }
          end
        end
      end

      def create
        @blog = current_post_type.new(post_params)
        @blog.user = current_user
        @blog.draft_user_id = current_user.id
        @blog.published_at = Time.now.utc
        authorize @blog

        respond_with @blog do |format|
          if @blog.save
            format.json { render :index }
          else
            format.json { render :new, status: :unprocessable_entity }
          end
        end
      end

      def destroy
        authorize @post
        @post.destroy
        flash[:notice] = I18n.t('flash.blogs.destroy.success') unless request.xhr?
        
        respond_with [:dashboard, @post] do |format|
          format.html{ redirect_to [:dashboard, Storytime::Page] }
        end
      end
      
    private
      def current_post_type
        @current_post_type ||= Storytime::Blog
      end
      helper_method :current_post_type
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
storytime-2.1.6 app/controllers/storytime/dashboard/blogs_controller.rb
storytime-2.1.5 app/controllers/storytime/dashboard/blogs_controller.rb
storytime-2.1.4 app/controllers/storytime/dashboard/blogs_controller.rb
storytime-2.1.3 app/controllers/storytime/dashboard/blogs_controller.rb
storytime-2.1.2 app/controllers/storytime/dashboard/blogs_controller.rb
storytime-2.1.1 app/controllers/storytime/dashboard/blogs_controller.rb
storytime-2.1.0 app/controllers/storytime/dashboard/blogs_controller.rb