Sha256: cd43cd4f1b144d5ec1d34058addd1dea849c512ed00ce83dee22f5f0a4de3e54

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

module Fuel
  class Admin::PostsController < ApplicationController
    http_basic_authenticate_with name: Fuel.configuration.username, password: Fuel.configuration.password

    def index
      @posts = Fuel::Post.all
    end

    def new
      @post = Fuel::Post.new
    end

    def create
      @post = Fuel::Post.new
      @post.tag = post_params["tag"]
      @post.author = post_params["author"]
      @post.content = post_params["content"]
      @post.title = post_params["title"]
      update_published

      if @post.save
        redirect_to admin_posts_path, notice: "Your blog post was successfully #{@message}."
      else
        render action: "new"
      end
    end

    def edit
      @post = Fuel::Post.find_by_slug(params[:id])
    end

    def update
      @post = Fuel::Post.find_by_slug(params[:id])
      @post.tag = post_params["tag"]
      @post.author = post_params["author"]
      @post.content = post_params["content"]
      @post.title = post_params["title"]
      update_published
      if @post.save
        redirect_to admin_posts_path, notice: "Post was updated and #{@message}"
      else
        render action: "edit"
      end
    end

    def destroy
      @post = Fuel::Post.find_by_slug(params[:id])
      @post.destroy
      redirect_to admin_posts_path, notice: "Post was successfully deleted"
    end

    def preview
      @content = params[:post][:content]
      respond_to do |format|
        format.js
      end
    end

    private

      def post_params
        params.require(:post).permit(:tag, :author, :content, :title)
      end

      def update_published
        @post.published = params[:commit] == "Save Draft" ? false : true
        @message = @post.published ? "posted" : "saved"
      end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fuel-0.3.2 app/controllers/fuel/admin/posts_controller.rb