Class: BlogBasic::BlogCommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/blog_basic/blog_comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/blog_basic/blog_comments_controller.rb', line 13

def create
  @blog_comment = @blog_post.blog_comments.new(params[:blog_comment])
  @blog_comment.user_id = current_user.id if current_user
  @blog_comment.request = request

  respond_to do |format|
    if @blog_comment.save
      flash[:notice] = 'Your comments has been posted.'
      format.html { redirect_to(@blog_post) }
      format.xml  { render :xml => @blog_comment, :status => :created, :location => @blog_comment }
    else
      format.html do
        @blog_comments = @blog_post.blog_comments.paginate(:page => params[:page], :order => 'created_at DESC')
        render :template => '../views/blog_posts/show.html.erb'
      end
      format.xml  { render :xml => @blog_comment.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/blog_basic/blog_comments_controller.rb', line 34

def destroy
  @blog_comment = BlogComment.find(params[:id])
  @blog_comment.destroy

  flash[:notice] = 'The comment has been deleted'

  respond_to do |format|
    format.html { redirect_to(blog_post_url(@blog_post)) }
    format.xml  { head :ok }
  end
end