Trouble with firefox and AJAX

I’ve been creating my own message board in rails as a learning
exercise. I’m currently trying to implement posting using AJAX, so the
topic page as a whole doesn’t need reloading.

What I’ve written works as epected in IE6 and Safari, but the AJAX
call fails silently in Firefox 1.5 – although the server has logged
the request, the “success” callback event seems never to trigger, and
there are no exceptions in the javascript console, and none in the
script/server output or logs.

I expect I’m doing something wrong here, but I’m at my wits end trying
to figure out what it is! If anyone can help me, I’d be very

Below are what I believe are the relevant file excerpts. What I’m
trying to achieve is this: when the user clicks “reply”, a form
appears at the bottom of the list of posts for them to use. If they
click “edit” on a post, the form is inserted before the post, and the
post is then deleted.

After typing their post, if they choose ‘save’, the saved post is
inserted before the form, then the form is deleted. If they choose
‘cancel’, the original post (or nothing if they’re making a new post)
is inserted before the form, then the form is deleted.

For debugging, I’ve removed the code to delete the posts and forms
from the page; I’ve also concentrated here on just the ‘cancel’ link,
as that shows the failure most simply. I’ve put debugging alerts on it
to indicate the state. When I click ‘reply’, the form (i.e. the
“cancel” link) is inserted as expected; when I then click on ‘cancel’,
Safari and IE seem to work fine, while Firefox pops up the ‘before’
and ‘after’ messages, and then nothing. The server logs show that the
post_view request is received and processed, so I’m stumped as to why
this fails. Any ideas?



==== forum_controller.rb ====

class ForumController < ApplicationController
def viewtopic
topic_id = params[:id].to_i
@topic = Topic.find(topic_id)
rescue ActiveRecord::RecordNotFound
flash[:notice] = “This topic does not exist”
redirect_to :action=>:index

    @posts = @topic.posts

# Post handling

def post_view
    if params[:id]
        @post = Post.find(params[:id])
        render :partial => "post", :object => @post
        # Do nothing for an unsaved post
        render :nothing => true

def post_edit
    if params[:save]
        # Create and save a Post from the form details
        @post = params[:post]

            render :partial => "post", :object => @post
        # Create a new Post or load one--to edit
        if params[:id]
            @post = Post.find(params[:id])
            @post = :topic_id=>params[:topic]

    render :partial => "post_form", :object => @post


==== viewtopic.rhtml ====

<%= render :partial => "post", :collection => @posts %>

<%= link_to_remote ‘Reply’, :update=>‘posts’, :position=>‘bottom’,
:url=>{ :action=>‘post_edit’, :topic=>@topic } %>

==== _post.rhtml ====

<%= post.posted_time %> <%= post.title %> <%= %>

==== _post_form.rhtml ====

<% post = post_form %>

<!-- cancelling should insert the post view (which is nothing for a
    cancelled new post) before the edit form -->
	<%= link_to_remote 'Cancel', :update=>'post_edit', 

:url=>{ :action=>‘post_view’, :id=>, :topic=>@topic },
:complete=>‘alert(“complete”);’ %>

==== end files ====

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs