Sha256: 66752df6f50d2ae0d981bf9bb98725991dd4b828918da529ba4dc0c0f8e06caa

Contents?: true

Size: 961 Bytes

Versions: 1

Compression:

Stored size: 961 Bytes

Contents

class Admin::PostsController < ApplicationController
  respond_to :html, :json

  load_and_authorize_resource :post

  def index
    @posts = Post.all
    respond_with( @posts )
  end

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

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

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

    if @post.update_attributes( post_params )
      flash[:notice] = "Post updated successfully"
    else
      flash[:notice] = "Post failed to update"
    end

    respond_with( [:admin, @post] )
  end

  def create
    @post = Post.new

    if @post.update_attributes( post_params )
      flash[:notice] = "Post created successfully"
    else
      flash[:notice] = "Post failed to update"
    end

    respond_with( [:admin, @post] )
  end


  private

  def post_params
    params[:post].slice( :title, :story_link, :draft, :published_at, :body )
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
engrave-1.0.0 app/controllers/admin/posts_controller.rb