Class: Blogit::CommentsController

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

Overview

Handles requests for creating Blogit::Comments

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationController

blogit_conf, #blogit_conf

Instance Attribute Details

#commentObject (readonly)

Accessor method for the comment being created

Returns a Blogit::Comment



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

def comment
  @comment
end

#postObject (readonly)

Accessor method for the Post we’re adding a Comment to

Returns Post



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

def post
  @post
end

Instance Method Details

#create {|comment| ... } ⇒ Object

Handles POST requests to /blogit/comments.html and /blogit/comments.js

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

Yields:



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

def create
  set_post_from_post_id
  set_comment_as_new
  comment.save
  yield comment if block_given?
  respond_to do |format|
    format.js   { create_respond_to_js }
    format.html { create_respond_to_html }
  end
end