Class: Admin::PostsController

Inherits:
ApplicationController
  • Object
show all
Includes:
BlogUrlHelpers
Defined in:
app/controllers/admin/posts_controller.rb

Instance Method Summary collapse

Methods included from BlogUrlHelpers

#admin_post_comments_path, #admin_post_path, #admin_post_post_comments_path, #admin_posts_path, #edit_admin_post_path, #new_admin_post_path, #post_archive_path, #post_category_archive_path, #post_category_path, #post_path, #posts_path

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
39
# File 'app/controllers/admin/posts_controller.rb', line 31

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

#destroyObject



41
42
43
44
45
46
# File 'app/controllers/admin/posts_controller.rb', line 41

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

#editObject



13
14
15
# File 'app/controllers/admin/posts_controller.rb', line 13

def edit
	respond_with @post
end

#indexObject



8
9
10
11
# File 'app/controllers/admin/posts_controller.rb', line 8

def index
	@posts = SpudPost.for_blog(params[:blog_key]).ordered.includes(:pending_comments, :author).paginate(:page => params[:page], :per_page => 15)
	respond_with @posts
end

#newObject



25
26
27
28
29
# File 'app/controllers/admin/posts_controller.rb', line 25

def new
	@categories = SpudPostCategory.ordered
	@post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id)
	respond_with @post
end

#updateObject



17
18
19
20
21
22
23
# File 'app/controllers/admin/posts_controller.rb', line 17

def update
	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