¿Cómo se envía un formulario de rails 3 sin actualizar la página?

I've seen this done using ajax & php, but not rails 3.

Intenté usar:

<%= form_for(:technician, :url => {:controller => 'pos', :action => 'create_ticket'}, :remote => true) do |f| %>  

but the page still refreshes each time. I'm building a point of sale program, so I don't want the page to refresh.

How do I send the form data to the controller to process and store in the database without refreshing?

preguntado el 09 de enero de 11 a las 12:01

Este código debemos send an ajax request, as long as you have a proper rails.js file included. Could you post the generated html code on pastebin.com? -

2 Respuestas

With Rails 3 and coming of the UJS, the simple fact of adding the remote attribute is sufficient to transform a request to AJAX.

But, for the request is handled as AJAX, this implies you have the Rails javascript library loaded.

That means, you should include the rails.js file on your header.

In your layout.erb.html, you should find

<%= javascript_include_tag :defaults %>

And in your public/javascripts directory, you should find :

application.js, controls.js, dragdrop.js, effects.js, prototype.js, rails.js

Entonces debería funcionar.

Respondido el 09 de enero de 11 a las 19:01

I have all those files and the code, but it still doesn't work. I have timers on the page and when I submit, the timer resets. - Anthony H

If in rails, you should make some file also in .js format and render it after save in controller. For example render create.js after save in create controller. In file create.js.erb, you should render back what you want to view after save that form

respondido 06 mar '12, 06:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.