views:

309

answers:

1

I have a remote_form_for that I use to let a user know if their form was submitted successfully. In this method I have :success=>'updateMain()

I would like to add an ajax update request to updateMain. The problem is that I can't find a way to make a single update request in rails (I know this is available in prototype).

The closest thing I've found is periodically_call_remote but this is not what I'm looking for as it continues to poll the server (and I only need it to happen once)

Another issue is that the ajax code needs to go into the updateMain js method, so I can't use periodically_call_remote as it automatically wraps the its js code with <script></script>.

I could write this manually with prototype but it would be nice to do it with rails. Any ideas?

A: 

In your controller method that your remote_form_for is submitting to, why don't you just use render :update?

def ajax_method
    # If the form was valid
    render :update do |page|
        page.replace_html 'id_of_div_to_update', :partial => 'successful_form_submission'
    end
end

The page will be updated each time you submit the ajax form.

nfm