Sha256: efa1d0a47f9b0aaac15cf09fe0f10858198d5b1f0d91c65086f8b7a34423f4a4

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

class Admin::PostsController < Admin::ApplicationController

	respond_to :html, :xml, :json
	before_filter :find_post, :only => [:show, :edit, :update, :destroy]
	add_breadcrumb 'Blog Posts', :admin_posts_path
	belongs_to_spud_app :blog_posts

	def index
		@posts = SpudPost.where(:is_news => false).order('published_at desc').includes(:pending_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] ||= []
		params[:spud_post][:updated_at] = Time.now()
		if @post.update_attributes(post_params)
			flash[:notice] = 'Post was successfully updated.'
		end
    respond_with @post, :location => 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 => [session[:admin_site] || 0])
		respond_with @post
	end

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

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

private

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

	def post_params
		params.require(:spud_post).permit(:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :category_ids => [], :spud_site_ids => [])
	end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_blog-1.1.2 app/controllers/admin/posts_controller.rb
tb_blog-1.1.1 app/controllers/admin/posts_controller.rb
tb_blog-1.1.0 app/controllers/admin/posts_controller.rb