Class: Spud::Admin::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



36
37
38
39
40
41
42
43
44
# File 'app/controllers/spud/admin/posts_controller.rb', line 36

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 => spud_admin_posts_path
end

#destroyObject



46
47
48
49
50
51
# File 'app/controllers/spud/admin/posts_controller.rb', line 46

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

#editObject



16
17
18
19
# File 'app/controllers/spud/admin/posts_controller.rb', line 16

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

#indexObject



11
12
13
14
# File 'app/controllers/spud/admin/posts_controller.rb', line 11

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

#newObject



30
31
32
33
34
# File 'app/controllers/spud/admin/posts_controller.rb', line 30

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

#updateObject



21
22
23
24
25
26
27
28
# File 'app/controllers/spud/admin/posts_controller.rb', line 21

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