I’m trying to post comments using Ajax. It seems that I have an
infinite loop somewhere, because it hangs on the return from the Ajax
call. The comment does get saved to the DB, but I have to refresh the
page for it to show.
The reason I know it’s some sort of infinite loop, is because I’m
showing a “loading.gif” image, and it never goes away. Plus, if the
comment doesn’t save, I’m returning an error message. I’ve posted the
code for the VIEW and CONTROLLER below. Please HELP!
#VIEW
<p>Name:<br/>
<%= text_field "comment", "name", :size => "20" %></p>
<p>Remark:<br/>
<%= text_area "comment", "entry", :rows => "7", :cols => "35"%></p>
<p><input type="submit" name="submit" id="form-submit-button"
value=“Post Remark” class=“btn” />
<%= end_form_tag %>
#CONTROLLER
def comments
post = Post.find(params[:id])
@comment = Comment.new(params[:comment])
post.comments << @comment
post.save
if @comment.save then
@comment_count = Comment.count(“post_id=#{params[:id]}”)
render_without_layout
else
render :text => “Error saving comment”
end
end