Sha256: b39d51f560a634dcfffb4ed633702ce8f7cc0a00900e51d4bcc5a12d1214a84f

Contents?: true

Size: 1.47 KB

Versions: 7

Compression:

Stored size: 1.47 KB

Contents

module Storytime
  module Dashboard
    class CustomPostsController < BlogPostsController

    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
      
    private
      def current_post_type
        @current_post_type ||= params[:post_type].classify.constantize
      end
      helper_method :current_post_type

      def load_posts
        @posts = policy_scope(Storytime::Post).page(params[:page_number]).per(10).where(type: current_post_type)
        
        @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

7 entries across 7 versions & 1 rubygems

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