views:

53

answers:

2

Hi Guys,

I have the fllowing requirement,

I have a model called Task to display user tasks

1 . Link to add a new task (in the tasks index page)

2 . when a user click the link, 'tasks/new' action will open up inside a popup

3 . when the user save the new task, I want to close 'new task' popup and refresh the parent page 'tasks/index' so that new task will display

I guess, i will have to execute a page reload java script at the end of 'tasks/create' action. But i'm not sure how to.

can anyone help me out to make this happen, thanks in advance

cheers, sameera

A: 

try window.opener.location.reload() in your case,if you know the index page's action,you can use redirect_to :action=>'index'

psjscs
hi psjscs, thanks for the reply. Bt how can i use window.opener.location.reload() inside the rails controller actiontasks/create,thanks again
sameera207
+1  A: 

Have your Task controller's create action redirect to the tasks index page as normal so that the newly created task shows up in the list. Then add a JavaScript onclick event handler to the Save button in the New Task popup. The event handler should simply perform a window.close(); to close the popup window when the Save button is clicked. If you're using the Prototype framework, it will be something like:

$("save").observe("click", function() {
  window.close();
});

Alternatively, use JavaScript to trap the new task form submission (onsubmit event) and close the popup window that way.

John Topley