Class: Blogit::PostsController

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

Overview

Handles requests for viewing Blogit::Posts

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationController

blogit_conf, #blogit_conf

Instance Attribute Details

#postObject (readonly)

The current Blogit::Post being displayed.

Returns a Blogit::Post with id from params



9
10
11
# File 'app/controllers/blogit/posts_controller.rb', line 9

def post
  @post
end

#postsObject (readonly)

The current Posts being displayed

Returns ActiveRecord::Relation for Post table



14
15
16
# File 'app/controllers/blogit/posts_controller.rb', line 14

def posts
  @posts
end

Instance Method Details

#index {|posts| ... } ⇒ Object

Handles GET requests to /blogit/posts.html, /blogit/posts.xml, and /blogit/posts.rss Possible formats include:

“XML” - calls #set_posts_for_feed. “RSS” - calls #set_posts_for_feed. “HTML” - calls #set_posts_for_index_page.

Yields #posts if called with a block (useful for calling super from subclasses)

Returns nil

Yields:



29
30
31
32
33
34
35
36
# File 'app/controllers/blogit/posts_controller.rb', line 29

def index
  respond_to do |format|
    format.xml  { set_posts_for_feed }
    format.rss  { set_posts_for_feed }
    format.html { set_posts_for_index_page }
  end
  yield(posts) if block_given?      
end

#show {|post| ... } ⇒ Object

Handles GET requests to /blogit/posts/:id.html

Yields #post if called with a block (useful for calling super from subclasses)

Yields:



41
42
43
44
# File 'app/controllers/blogit/posts_controller.rb', line 41

def show
  set_post
  yield post if block_given?
end

#tagged {|posts| ... } ⇒ Object

Handles GET requests to /blogit/posts/tagged/:tag.html. Renders the index template with Posts tagged with tag in tag parameter

Yields #posts if called with a block (useful for calling super from subclasses)

Yields:



50
51
52
53
54
# File 'app/controllers/blogit/posts_controller.rb', line 50

def tagged
  set_posts_for_tagged_page
  yield(posts) if block_given?      
  render :index
end