You need to separate things that are server-side (Rails, controllers, actions) and the client side (pop-ups, JavaScript, send requests).
Your client-side actions (JavaScript code) should think of your Rails application as some server that returns some responses for some requests. From a JavaScript perspective, it doesn't matter if the Rails or Smalltalk server is running.
The basic workflow for your popup may be:
1) open a new window . This requires JavaScript client activity. Use the window.open function or (I humbly consider this method as the best) to create a new <div> and draw it using CSS so that it covers (a good effect is a translucent background: background: #ddf; opacity: 0.5; through which you still see the contents of the page).
2) fill in the window using the edit form . Here, your client side of the script should make an AJAX-like call (not necessarily real AJAX, since in this case a synchronous request might be reasonable) to get the edit form from your Rails application. See this simplified example:
function fillPopupBody(popup) { var req = new XMLHttpRequest(); req.open("GET","/something/partial_new_form.html",false); // Synchronic request! req.send(null); if( req.status == 200 ) { popup.innerHTML = req.responseText; return true; } else { popup.innerHTML = "<p class='error'>"+req.status+" ("+req.statusText+")</p>"; return false; } }
3) Prepare the action that returns the form in the Rails application - (on the server side) Usually it can be your new action of this resource controller, but is displayed without a layout.
An alternative approach would be to create the form using JavaScript (without selecting it separately) or to include it always on the page - just hidden by default, so JavaScript only needs to set its display property.
4) Submission of the form form - you probably want the user to stay on one page, so you need to intercept the form submission. Just add a handler to the "send" event of the created form, build a request, publish it, check the server response.
The answer will be returned by Rails, in your opinion: create an action . Perhaps you already have this, because the code ./script/rails generate scaffold by ./script/rails generate scaffold is usually ok.
If the answer is 201 (created), you can close the pop-up window ( display: none ) and refresh the page to display a new object — either refresh the entire page or extract only the changed parts.
If the create action cannot create an object, the default response code is 422 (an unprocessed object), and the content is a model error object displayed as JSON or XML. Just show errors in the form (let your JavaScript specify innerHTML some predefined element).
It was a "manual" way of completing a task. I have a disgust (hardly explainable ;-) in JavaScript libraries, and I prefer working directly with the DOM. You can find many Rails helpers that save you from writing JavaScript code. I think finding a parameter :remote => true form_for would be a good starting point.
The jQuery documentation ( http://docs.jquery.com/Main_Page ) can also be well read.
Concluding this long story, here is a short answer to your questions from the comment:
How to link controller actions with popup?
: by sending an HTTP request to the correct URL: "GET / users / 1 / notes / new", "POST / user / 1 / notes"
How to close a popup?
: By setting display: none if the popup is a page element or by calling window.close() if your popup is a separate window.