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?

2
  • 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? Commented Jun 22, 2012 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... Commented Jun 22, 2012 at 21:29

1 Answer 1

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.