Class: PostsController

Inherits:
ApplicationController show all
Defined in:
lib/forge/app/controllers/posts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#app_init

Instance Method Details

#categoryObject



25
26
27
28
29
30
31
# File 'lib/forge/app/controllers/posts_controller.rb', line 25

def category
  @post_category = .find(params[:id])
  @page_title = "Latest News | " + @post_category.title
  @posts = @post_category.posts.posted.paginate(:per_page => 6, :page => params[:page])
  session[:page] = params[:page] if params[:page]
  render :template => "posts/index"
end

#feedObject



42
43
44
45
46
47
# File 'lib/forge/app/controllers/posts_controller.rb', line 42

def feed
  @posts = Post.posted.all(:order => "created_at DESC", :limit => 10)
  respond_to do |format|
    format.rss
  end
end

#indexObject

TODO: re-enable caching caches_page :index, :feed



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/forge/app/controllers/posts_controller.rb', line 7

def index
  @page_title = "Latest News"
  @posts = Post.posted
  if params[:month] && params[:year] # get posts based on archive month
    start_date = Time.parse("#{params[:year]}-#{params[:month]}-01")
    end_date = start_date + 1.month
    @posts = Post.posted.where("created_at >= ? AND created_at <= ?", start_date, end_date)
    @page_title += " | #{start_date.strftime("%B %Y")}"
  end
  @posts = @posts.paginate(:per_page => 6, :page => params[:page])
  session[:page] = params[:page] if params[:page]

  respond_to do |format|
    format.html {}
    format.mobile { render :template => "mobile/posts" }
  end
end

#previewObject



49
50
51
52
# File 'lib/forge/app/controllers/posts_controller.rb', line 49

def preview
  @post = Post.new(params[:post])
  render :action => :show
end

#showObject



33
34
35
36
37
38
39
40
# File 'lib/forge/app/controllers/posts_controller.rb', line 33

def show
  @post, @page_title = get_post
  @comment = Comment.create_comment(@post, session[:comment]) if @post.allow_comments?
  respond_to do |format|
    format.html {}
    format.mobile { render :template => "mobile/post" }
  end
end