I have opened the view template as popup by using the following code:
<%= link_to 'New User', "/users/new", :method => :get, :target => "_blank" %>
controller code:
def new
render :layout => false
end
the new.html.erb is having few textboxes and buttons as Save and Cancel
My problem is how can i close the popup upon clicking Save or Cancel button?
Thank u,
Sudhir C.N.
This a more a javascript question rather than one specific to Rails.
Your Cancel button is easy enough, something like:
(stolen from http://snippets.dzone.com/posts/show/267)
Your submit button shouldn’t change. It will need to POST to your controller as normal. The successful response rendered by the controller should display a “Success” message in the flash and could then close the window automatically after, say, three seconds:
This is a pretty simple solution. Maybe consider investigating some popup libraries for either prototype or jquery (depending on the library you’re using). Not sure whether modern popup blockers render these D.O.A. though. Your
target="_blank"approach should play nice with popup blockers.Edit: if you’re using jquery maybe consider something like the modal dialog: http://jqueryui.com/demos/dialog/#modal-form