Sha256: 3f6a7fcbb74cab9c1a8669af2f51160f655a3a10c6dfa3523c5925535d2ede34

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

require_dependency "wafflemix/application_controller"

module Wafflemix
  class Admin::PostsController < ApplicationController

    layout 'wafflemix/admin'

    def index
      @posts = Post.all

      respond_to do |format|
        format.html
        format.json { render json: @posts }
      end
    end

    def show
      @post = Post.find(params[:id])

      respond_to do |format|
        format.html
        format.json { render json: @post }
      end
    end

    def new
      @post = Post.new
      @post.build_meta_content

      respond_to do |format|
        format.html
        format.json { render json: @post }
      end
    end

    def edit
      @post = Post.find(params[:id])

      unless @post.meta_content
        @post.build_meta_content
      end
    end

    def create
      @post = Post.new(params[:post])

      respond_to do |format|
        if @post.save
          format.html { redirect_to @post, notice: 'Post was successfully created.' }
          format.json { render json: @post, status: :created, location: @post }
        else
          format.html { render action: "new" }
          format.json { render json: @post.errors, status: :unprocessable_entity }
        end
      end
    end

    def update
      @post = Post.find(params[:id])

      respond_to do |format|
        if @post.update_attributes(params[:post])
          format.html { redirect_to @post, notice: 'Post was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: "edit" }
          format.json { render json: @post.errors, status: :unprocessable_entity }
        end
      end
    end

    def destroy
      @post = Post.find(params[:id])
      @post.destroy

      respond_to do |format|
        format.html { redirect_to posts_url }
        format.json { head :no_content }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wafflemix-0.0.4 app/controllers/wafflemix/admin/posts_controller.rb
wafflemix-0.0.3 app/controllers/wafflemix/admin/posts_controller.rb
wafflemix-0.0.2 app/controllers/wafflemix/admin/posts_controller.rb
wafflemix-0.0.1 app/controllers/wafflemix/admin/posts_controller.rb