5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/comments_controller.rb', line 5
def create
@post = Post.find(params[:post_id])
@comment = Comment.new(params[:comment])
@comment.user = current_user
@comment.request = request
@comment.post = @post
if @comment.save
respond_to do |format|
format.html do
if @comment.approved?
flash[:notice] = 'Create successful!'
else
flash[:notice] = "Your comment looks like spam, it will show up once it's been approved."
end
redirect_to post_path(@post, :anchor => dom_id(@comment))
end
format.js do
if @comment.approved?
render @comment, :content_type => :html
else
render :text => "Your comment looks like spam, it will show up once it's been approved.", :status => 406, :content_type => :html
end
end
end
else
respond_to do |format|
format.html { render :action => "new" }
format.js { render :text => @comment.errors.full_messages.join(', ').capitalize, :status => 403, :content_type => :html }
end
end
end
|