Ruby on Rails: image_submit_tag and :confirm

by dom111 on August 14th, 2008

I was told about an issue today with the image_submit_tag not supporting the :confirm method on the element:

1
<%= image_submit_tag('buttons/submit.gif', { :confirm => 'Are you sure?' }) %>

so I thought I’d share a quick fix which would be the actual javascript returned by the function:

1
2
<%= image_submit_tag('buttons/submit.gif', { :onclick => 'return
confirm(\'Are you sure?\');' }) %>

Hope this can save some people time…

2 Comments
  1. Ashok permalink

    Thanks for the suggestion above.

    But, in the confirmation dialog, it displays the url, like “The page at http://fhnd5.joyent.com:3000 says ‘Are you sure’” – I dont want this url displayed as the heading. How do I avoid that?

    Thanks
    Ashok

    • Hi Ashok,

      By the sounds of it, you’re using Firefox, which automatically displays the url of the site in any alert/confirm javascript box. I guess it’s for security, so you can tell the message box is coming from the site you think it is… I’m not sure if there any way to get around that, short of writing your own alert/confirm system…

      Sorry!

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS