Class: PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PostsController
- Defined in:
- lib/forge/app/controllers/posts_controller.rb
Instance Method Summary collapse
- #category ⇒ Object
- #feed ⇒ Object
-
#index ⇒ Object
TODO: re-enable caching caches_page :index, :feed.
- #preview ⇒ Object
- #show ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#category ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/forge/app/controllers/posts_controller.rb', line 25 def category @post_category = PostCategory.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 |
#feed ⇒ Object
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 |
#index ⇒ Object
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 |
#preview ⇒ Object
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 |
#show ⇒ Object
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 |