Class: Spud::Admin::NewsPostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

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

#destroyObject



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

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

#editObject



15
16
17
18
# File 'app/controllers/spud/admin/news_posts_controller.rb', line 15

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

#indexObject



10
11
12
13
# File 'app/controllers/spud/admin/news_posts_controller.rb', line 10

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

#newObject



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

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

#updateObject



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

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