RJS confirmation popup

Hi everyone,

In my app users can save queries. I want to warn them if they are
about to overwrite an existing query (same name). I wanted to do this
with a confirm javascript popup.

My question is: Is it possible to generate a confirmation popup from
an RJS template and then somehow get the answer back? To know if my
controller should overwrite the query or just discard the changes.

Up until now, I didn't find a way to generate a confirmation popup
through RJS, except with the call method to call a javascript method
that will generate this for me...but I was hoping for something a bit
more ruby...and it doesn't solve the problem of getting the answer back
to the controller.

Thank you,


Do the pop-up before the Ajax post

:confirm => ‘Are you sure you want to save this?’

I’m assuming that you can easily check for existing queries when this page loads and make the confirm conditional.


First of all you should make sure you’re replying to the list and not to the person who posted.

As for making the confirm conditional, you need to generate the options hash before it’s used. e.g.:

<%= form_remote_tag(:url => {:action => ‘save_query’},

                :confirm => 'Are you sure you want to overwrite this?',
                :html => {:id => 'save_query_form'}) %>


<% options = { :url => {:action => ‘save_query’}, :html => {:id => ‘save_query_form’} } %>

<% options[:confirm] = “Are you sure…” if some_condition_here %>

<%= form_remote_tag( options ) %>


Ah I never even realized that you could pass the options like that.
But unfortunately it doesn't exactly work in my case. The problem is
that the condition is not only server-side, but it depends on what the
user enters as the name of the search:

<%= form_remote_tag(:url => {:action => 'save_query'},
                    :confirm => 'Are you sure you want to overwrite
                    :html => {:id => 'save_query_form'}) %>

    <%= submit_tag 'Save query as'%>
    <%= text_field 'search', 'name' %>
<%= end_form_tag %>

So if the text in the text_field 'search[name]' matches any of the
queries saved on the server.

So basically the query list is on the server side, but the name of the
new server is on the client (browser) side.

Any idea how this could be done?