Simple UJS Fields

Hello,

I have the view:

<% form_tag ‘/’ do %>
<%= number_field_tag(:number_one) %>
<%= number_field_tag(:number_two) %>
<%= submit_tag ‘Calculate’ %>
<% end %>
<%= @number %>

and the controller:

def add
numberone = params[:number_one].to_f
numbertwo = params[:number_two].to_f
@number = numberone + numbertwo
end

I am trying to learn some ujs in rails with this example, but I can’t
get it to work. I would like it to not refresh the page to load @number
unobtrusively. Every time I try the submit_tag just stops working. I
have read many tutorials and such teaching how to get form_for forms to
use javascript, but not an example as simple as mine. Should I create a
.js file named add.js? ect. ect.

Point me in the right direction?

Thanks

Do you mean Ajax, or UJS? UJS is unobtrusive JavaScript which means the
JavaScript handling code is decorated on the HTML AFTER the page loads
so that it doesn’t make the HTML invalid and so that things like Braille
readers still work with it.

RJS on the other hand is Ajax where parts of the page are updated
independently of the whole page.

You say UJS but you talk as if you mean AJAX using RJS templates.

There are good simple examples all over the web for both of these.

Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r
Learn: http://sensei.zenunit.com/
New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy
process! Check it out now!