Hi, I’ve got a real head-scratcher. I’ve got a standard Ajax form using
form_remote_tag, which calls a controller action which adds a comment
and then sends back some JS via RJS which updates a few items on the
page.
It did work fine but (and I’ve no idea what has happened) now it
doesn’t. It calls the controller action but gets an empty response back
and then redirects (it seems) to the controller directly, thus rendering
the javascript in plain text.
If I get rid of the RJS and render a partial and use :update =>
“comments” in my form_remote_tag then it does the same thing but renders
the html partial.
You can check it out by going to the site itself at
http://indecipherable.co.uk/home/index/welcome-to-indecipherable/
Click add comment to show the form and off you go.
The server is mongrel (on my dev box as well, though it does the same
with webrick).
I’ve looked at Firebug and the request goes off ok but no responseText
comes back.
The RJS code looks like this
page.visual_effect “BlindUp”, “add-comment”
page.insert_html :top, “comments”, :partial =>
“/common/comments/comment”, :object => @comment
page.show “show-comment”
page.replace_html “comment-count”,
pluralize(@comment.entry.comments.count, “Comment”)
page[:latest].visual_effect :highlight, :startcolor => “#ffffff” #,
:endcolor => “#b1d0e9”
The controller action looks like this
def comment
@comment = Comment.new(:text => params[:text])
@comment.user = User.find(:first)
@comment.entry = Entry.find_by_identifier(params[:entry])
if (@comment.save)
@latest_comment = @comment
# render :partial => “/common/comments/comment”, :object => @comment
This fails too
else
render :action => “show”
end
end
The form looks like this
<% form_remote_tag(:url => { :action => :comment },
:html => {:class => “margin-form” }) do %>
Your Comment:
<%= text_area_tag(:text, “”, :rows => 4, :cols => 50) %>
<%= submit_tag(“add your comment »”, :class => “submit”,
:disable_with => “Sending comment…”) %>
<% end %>
I’ve searched high and low and found a few similar stories but every
time the reason for the odd behaviour hasn’t been related to my code,
which seems to be pretty boilerplate to me.
Thanks for any help.