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



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

def create
	@categories = SpudPostCategory.grouped
	@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



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

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



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

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

#updateObject



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

def update
	@categories = SpudPostCategory.grouped
	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