Class: PostsController

Inherits:
ApplicationController
  • Object
show all
Includes:
BlogUrlHelpers
Defined in:
app/controllers/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

#archiveObject



54
55
56
57
58
59
# File 'app/controllers/posts_controller.rb', line 54

def archive
  @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
  respond_with @posts do |format|
    format.html { render view_for_action 'index' }
  end
end

#categoryObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/posts_controller.rb', line 31

def category
  page = 1
  if params[:page].blank? == false
    page = params[:page].to_i
    if page.to_s != params[:page].to_s
      if(page > 1)
        redirect_to (:page => page),:status => :moved_permanently and return
      else
        redirect_to (:page => nil),:status => :moved_permanently and return
      end
    end
  end
  if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
    @posts = @post_category.posts.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(:page => page, :per_page => Spud::Blog.config.posts_per_page)
  else
    redirect_to posts_path
    return
  end
  respond_with @posts do |format|
    format.html { render view_for_action 'index' }
  end
end

#create_commentObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/posts_controller.rb', line 70

def create_comment
  unless params[:comment_validation].blank? # trap spam bots
    render :nothing => true
    return
  end
  @comment = @post.comments.new(comment_params)
  @comment.user_agent = request.env["HTTP_USER_AGENT"]
  @comment.user_ip = request.remote_ip
  @comment.referrer = request.referrer
  @comment.approved = Spud::Blog.default_comment_approval
  @comment.permalink = post_path(@post.url_name)
  if @comment.save
    if @comment.approved?
      flash[:notice] = 'Your comment has been posted.'
    else
      flash[:notice] = 'Your comment has been saved and will appear after being reviewed by an administrator.'
    end
    @comment = SpudPostComment.new()
  end
  respond_with @comment do |format|
    format.html { render view_for_action 'show' }
  end
end

#filterObject

The sole purpose of this action is to redirect from a POST to an seo-friendly url



19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/posts_controller.rb', line 19

def filter
  if !params[:category_url_name].blank? && !params[:archive_date].blank?
    redirect_to (params[:category_url_name], params[:archive_date])
  elsif !params[:category_url_name].blank?
    redirect_to (params[:category_url_name])
  elsif !params[:archive_date].blank?
    redirect_to post_archive_path(params[:archive_date])
  else
    redirect_to posts_path
  end
end

#indexObject



9
10
11
12
13
14
15
16
# File 'app/controllers/posts_controller.rb', line 9

def index
  @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).ordered.paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
  respond_with @posts do |format|
    format.html{
      render view_for_action('index')
    }
  end
end

#showObject



61
62
63
64
65
66
67
68
# File 'app/controllers/posts_controller.rb', line 61

def show
  if @post.comments_enabled
    @comment = SpudPostComment.new()
  end
  respond_with @post do |format|
    format.html { render view_for_action 'show' }
  end
end