# Has anyone seen how to do pop-ups via controllers?

**URL:** <https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199>\
**Category:** Rails\
**Created:** [June 11, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199 "2008-06-11T20:54:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [June 11, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199/1 "2008-06-11T20:54:15Z")

</div>

I’ve got the pop-up window opening if I click on a link, but now I want  
to do something else. After a record is created, I want to go the edit  
page and open up a pop-up window. Any ideas on how to make that work?

Thanks!

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [June 12, 2008, 8:42am UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199/2 "2008-06-12T08:42:06Z")

</div>

Hi

Its not the right method to call a popup from controller…IF you want  
to do that u an put onwindow load u can call the function of popup on  
the edit page.

Thanks

Dhaval P.  
Software Engineer

> **[RailsHouse : Ruby on Rails Development & Consulting, Waterloo, Canada](https://railshouse.com)**
>
> RailsHouse is Waterloo, Ontario based Ruby on Rails Consultancy firm which provides RoR Development, Migration, Staffing, Maintenace and Support Services

sales(AT)railshouse(DOT)com

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [June 12, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199/3 "2008-06-12T17:45:36Z")

</div>

> Prior to opening the pop-up window I need to save a new record. What’s  
> the best way to open that window after a record has been successfully  
> saved. If it fails, that window should not open.

What Dhaval is saying is that a server cannot directly request that a  
browser open a pop-up window–the request must come from the browser.  
Believe me, everyone except spammers are very glad that is the case.

What you may be able to do is use RJS templates to send a javascript  
pop-up script to the browser (or simply an alert() depending on your  
requirements).

– Mark.

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [June 12, 2008, 4:54pm UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199/4 "2008-06-12T16:54:23Z")

</div>

> Its not the right method to call a popup from controller…IF you want  
> to do that u an put onwindow load u can call the function of popup on  
> the edit page.

Prior to opening the pop-up window I need to save a new record. What’s  
the best way to open that window after a record has been successfully  
saved. If it fails, that window should not open.

thanks.

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [June 12, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199/5 "2008-06-12T19:00:15Z")

</div>

> After a record is created, I want to go the edit  
> page and open up a pop-up window. Any ideas on how to make that work?

What are you calling a popup? I don’t know anyone that doesn’t have a  
popup blocker.

Without a redirect, I think you could do this with a YUI panel or  
extJS panel that gets opened based on the results of an AJAX call.

However, if I hear you correctly, “Go to the edit page” is a redirect  
which makes this easier. You have a new page!

I haven’t done this, but if you are going redirect to a new (edit)  
page, I should think that you could pass a parameter to the “edit  
view” that tells the view to open a YUI panel Like this:

[http://developer.yahoo.com/yui/examples/container/panel-resize\_source.html](http://developer.yahoo.com/yui/examples/container/panel-resize_source.html)

Good luck

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [June 12, 2008, 7:20pm UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199/6 "2008-06-12T19:20:05Z")

</div>

> What are you calling a popup? I don’t know anyone that doesn’t have a  
> popup blocker.
> 
> Without a redirect, I think you could do this with a YUI panel or  
> extJS panel that gets opened based on the results of an AJAX call.
> 
> However, if I hear you correctly, “Go to the edit page” is a redirect  
> which makes this easier. You have a new page!

This is actually an internal application so the pop-up window is not a  
problem. The pop-up window is pick list to add to an order. The pop-up  
list works off of an order number so if it’s a new order, an order needs  
to be created first. After the new order is created, I want to refresh  
the order page so that it’s in edit mode to continue entering in the  
order AND enable the user to select values in the pop-up window.

Does that make sense?

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [June 12, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199/7 "2008-06-12T23:19:40Z")

</div>

> What you may be able to do is use RJS templates to send a javascript  
> pop-up script to the browser (or simply an alert() depending on your  
> requirements).

I am getting an error somewhere and am not sure what it means.

I have this in my template - \<%= javascript\_include\_tag :defaults -%\>

I’m guessing that this is an error in my controller.

def create  
respond\_to do |format|  
format.html {render :update do |page|  
page.call(‘popup’)  
end  
}  
end  
end

I then get this output on the following page

try {  
popup();  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘popup();’);  
throw e }

Any help to fix what I’m doing wrong is appreciated.

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [June 13, 2008, 6:51am UTC](https://www.ruby-forum.com/t/has-anyone-seen-how-to-do-pop-ups-via-controllers/140199/8 "2008-06-13T06:51:40Z")

</div>

That looks like you are sending an ajax response to a normal page  
request. ie. did the request come from a browser ajax call, or a  
normal link or form submit. To send javascript to the page using the  
render :update, you need to use link\_to\_remote or form\_remote etc. in  
your view.

> try {  
> popup();} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘popup();’);
> 
> throw e }
> 
> ## Any help to fix what I’m doing wrong is appreciated.
> 
> Posted viahttp://www.ruby-forum.com/.

As regards your popup question, the earlier suggestion from Dvahal of  
using the javascript onwindow load in your Edit view would seem a fair  
way to go. In the edit template, you can conditionally include the  
javascript call depending on whether the order being displayed is  
considered a new one.

Tonypm
