Sha256: dac819b63bfc18d229b10a969897f1db56d6025aa2cf700c057d080d19c10451

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 KB

Contents

class Spud::Admin::PostsController < Spud::Admin::ApplicationController

	layout 'spud/admin/post'
	respond_to :html, :xml, :json
	before_filter :find_post, :only => [:show, :edit, :update, :destroy]
	add_breadcrumb 'Blog Posts', :spud_admin_posts_path
	belongs_to_spud_app :blog_posts
	cache_sweeper :spud_post_sweeper, :only => [:create, :update, :destroy]

	def index
		@posts = SpudPost.where(:is_news => false).order('published_at desc').includes(:comments, :author).paginate(:page => params[:page], :per_page => 15)
		respond_with @posts
	end

	def edit
		@categories = SpudPostCategory.grouped
		respond_with @post
	end

	def update
		@categories = SpudPostCategory.grouped
		params[:spud_post][:spud_site_ids] ||= []
		if @post.update_attributes(params[:spud_post])
			flash[:notice] = 'Post was successfully updated.'
		end
    respond_with @post, :location => spud_admin_posts_path
	end

	def new
		@categories = SpudPostCategory.grouped
		@post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id, :spud_site_ids => [current_site_id])
		respond_with @post
	end

	def create
		@categories = SpudPostCategory.grouped
		params[:spud_post][:spud_site_ids] ||= []
		@post = SpudPost.new(params[:spud_post])
		if @post.save
	    flash[:notice] = 'Post was successfully created.'
		end
    respond_with @post, :location => spud_admin_posts_path
	end

	def destroy
		if @post.destroy
	    flash[:notice] = 'Post was successfully deleted.' 
		end
    respond_with @post, :location => spud_admin_posts_path
	end

	private

	def find_post
		@post = SpudPost.find(params[:id])
		if @post.blank?
			flash[:error] = "Post not found!"
			redirect_to spud_admin_posts_path and return false
		end
	end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spud_blog-0.8.17 app/controllers/spud/admin/posts_controller.rb
spud_blog-0.8.16 app/controllers/spud/admin/posts_controller.rb
spud_blog-0.8.15 app/controllers/spud/admin/posts_controller.rb
spud_blog-0.8.14 app/controllers/spud/admin/posts_controller.rb
spud_blog-0.8.13 app/controllers/spud/admin/posts_controller.rb