Sha256: 04cdc04d0c9198a3fe49de09946edf2c8a6aaf07b910f9639d71b27f6fecce9a

Contents?: true

Size: 1.75 KB

Versions: 8

Compression:

Stored size: 1.75 KB

Contents

module Storytime
  module Dashboard
    class BlogPostsController < PostsController

      def new
        @post = current_post_type.new
        @post.blog = Storytime::Blog.friendly.find(params[:blog_id])
        @post.user = current_user
        authorize @post
      end

      def create
        @post = current_post_type.new(post_params)
        @post.blog = Storytime::Blog.friendly.find(params[:blog_id])
        @post.user = current_user
        @post.draft_user_id = current_user.id
        authorize @post

        if @post.save
          @post.create_autosave(post_params.slice(:draft_content)) if params[:preview] == "true"

          send_subscriber_notifications if @post.published? && post_params[:notifications_enabled] == "1"

          opts = params[:preview] == "true" ? { preview: true } : {}

          redirect_to [:edit, :dashboard, @post, opts], notice: I18n.t('flash.posts.create.success')
        else
          load_media
          render :new
        end
      end

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

      def load_posts
        @posts = policy_scope(Storytime::Post).page(params[:page_number]).per(10)

        @posts = if params[:published].present? && params[:published] == 'true'
          @posts.published.order(published_at: :desc)
        else
          @posts.draft.order(updated_at: :desc)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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