Sha256: a8eebeeeb2829e87c77341e75da59efa05722291281040689fb6d31126120a8d

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController

	layout 'spud/admin/post'
	respond_to :html, :xml, :json
	before_filter :find_post, :only => [:show, :edit, :update, :destroy]
	add_breadcrumb 'News Posts', :spud_admin_news_posts_path

	belongs_to_spud_app :news_posts

	def index
		@posts = SpudPost.where(:is_news => true).order('published_at desc').includes(:comments).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
		if @post.update_attributes(params[:spud_post])
	    flash[:notice] = 'News Post was successfully updated.'
			expire_news_actions(@post)
	  end
    respond_with @post, :location => spud_admin_news_posts_path
	end

	def new
		@categories = SpudPostCategory.grouped
		@post = SpudPost.new(:published_at => Date.today, :spud_user_id => current_user.id, :is_news => true, :comments_enabled => false)
		respond_with @post
	end

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

	def destroy
		if @post.destroy
	    flash[:notice] = 'News Post was successfully deleted.'
	    expire_news_actions(@post)
		end
    respond_with @post, :location => spud_admin_news_posts_path
	end

	private

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

	def expire_news_actions
		expire_action news_url
		expire_action news_post_url(@post.url_name) unless @post.nil?
	end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spud_blog-0.6.0 app/controllers/spud/admin/news_posts_controller.rb