0

The project I'm working on renders several pages (such as login pages and signup forms) as modals, which is accomplished by giving those links the class .modal so the following piece of JavaScript would trigger:

$('.modal').click(function(){
    var url = this.href;
    var dialog = $('<div id="modal" style="display:none"></div>').prepend('#barhappy_container');
    dialog.load(url, function(){
        dialog.dialog({
            modal: true,
            draggable: false,
            position: 'center',
            dialogClass: 'no-title',
            width: 'auto',
/*          height: 'auto', */
            resizable: false,
            open: function(){
                $.getScript('/assets/modal/in-modal-open.js');
            },
            close: function(event, ui){
                dialog.remove();
            }
        });
    });     
    return false;
});

However, I now need a page rendered by a Controller to display the same way, but there's no link to click that can be given the class .modal.

So, is there a way to call this JavaScript function from my Rails controller and pass it the proper parameters?

Adam Templeton
  • 4,467
  • 7
  • 27
  • 39
  • If the page is not reached by clicking a link, how is it reached? And, if you want the page to appear in a modal dialog, what page will that dialog float above? – Jacob Mattison Jun 22 '12 at 21:06
  • It's a modal popup that floats above the contact form when you've submitted a new message saying 'thanks for the message' or something similar... – Adam Templeton Jun 22 '12 at 21:29

1 Answers1

3

Figured it out!

I added a js file to my contact_messages view folder called create.js.erb.

Then I had my Contact Messages controller activate that js file with a respond_to block.

Inside the js file, I called a variation of the modal function...

Adam Templeton
  • 4,467
  • 7
  • 27
  • 39