From: "Jesús Gabriel y Galán" Date: 2013-08-04T22:54:19+09:00 Subject: Re: Capture HTML table data, pass to Ruby, pass back and display result in HTML text field On Sun, Aug 4, 2013 at 2:55 PM, Hubert Wagner wrote: > Hello : > I need advice on how to proceed : > > Given a table 6 x 30 rows. A typical row as follows : > > Cell A (text) - Cell B (text) - Cell C (checkbox) - Cell D (number) - > Cell E (number) - Cell F (if C = true, D * E else O) > > Cell F contains a Sub-Total for that row. > Cell F(n) contains the grand total - Sum of Cells F1 to Fn-1 > > The Ruby code does the following ; > 1 If a checkbox is changed, calculate value of Cell F in the same row > and update the contents of the field. > However, Ruby would need to check constantly the status of each > checkbox. This sounds like a bad way to do this. Ideally, on change, the > checkbox would send a message to Ruby, but how?. > > 2 Update the value of Cell F(n) > (Cell F names could be numeric 1 to n-1 so Ruby could loop through and > sum the list) > > I suppose the Sub-Total cells and the Grand Total cell would contain an > ERB : <% calculated value %> > > However, I don’t see how the ERBs in Sub-Total/Grand Total could update > the table once the page has been rendered. > > If item 1 above isn’t possible, the page could remain dormant until the > user clicks on a button to calculate the Grand Total. > I have the table. However, I don’t know where to begin with Ruby. (I’m > doing this in RubyFrontier). I don't know what RubyFrontier is, but if I understand correctly, you have a web application that generates an HTML table with data, and you want the user to interact with the data, have Ruby calculate some things and have the HTML updated with the result of the calculation. To do that, I'd do it with some javascript on the page that executed on the events that you wanted, like when a checkbox changed or a button is pressed or whatever. In that javascript you could call the Ruby web app via AJAX, have the Ruby code calculate new values and send them as the response of the AJAX call. Then, the javascript would take this response and update the HTML page via DOM manipulation. There are javascript libraries such as jQuery that ease all of this work. Hope this helps, Jesus.