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
<div id="cmnts-form">
<div id="add-comment">Have something to say?</div>
<%= form_remote_tag(
:url => {:controller => ''journal'',
:action => ''comments'',
:id => entry.id},
:update => {:success => "new-comment"},
:loading => "Element.show(''loading'');",
:success => "Element.hide(''loading'');",
:complete => "clearText();",
:position => "bottom"
) %>
<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" />
<img id="loading" src="../images/loading.gif"
alt="" style="display:
none;" /></p>
<%= end_form_tag %>
</div>
#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
--
Posted via http://www.ruby-forum.com/.