Simple UJS Fields


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

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?


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.

New video up now at real fastcgi rails deploy
process! Check it out now!