Sha256: 465ec8ca6fc4d7ce1274aa8428dad301d9724fa332cb1154f04ea91ea861303d

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

module Exposition
  module Concerns
    module Controller
      module Admin
        module PostsController
          extend ActiveSupport::Concern
          def index
            @posts = Post.sorted_by_published_date.
              page(params[:page]).
              per(25)
          end

          def new
            @post = Post.new
            find_authors
            find_tags
          end

          def create
            @post = Post.new(post_params)
            find_authors
            find_tags
            if @post.save
              flash[:success] = "Post successfully created."
              redirect_to admin_posts_path
            else
              render :new
            end
          end

          def edit
            find_post
            find_authors
            find_tags
          end

          def update
            find_post
            find_authors
            find_tags
            if @post.update(post_params)
              flash[:success] = "Post was successfully updated."
              redirect_to admin_posts_path
            else
              render action: 'edit'
            end
          end

          private

          def find_authors
            @authors = User.all
          end

          def find_post
            @post = Post.find_by_slug!(params[:id])
          end

          def find_tags
            @tags = Categorical::Tag.all
          end

          def post_params
            params.require(:post).permit(:id, :title, :body, :summary, :slug, :published, :author_id, tag_ids: [])
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
exposition-0.0.5.7.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb
exposition-0.0.5.6.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb
exposition-0.0.5.5.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb
exposition-0.0.5.4.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb
exposition-0.0.5.2.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb
exposition-0.0.5.1.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb
exposition-0.0.5.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb
exposition-0.0.4.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb
exposition-0.0.3.pre.alpha lib/exposition/concerns/controllers/admin/posts_controller.rb