[#409331] Capture HTML table data, pass to Ruby, pass back and display result in HTML text field — Hubert Wagner <lists@...>

Hello :

11 messages 2013/08/04

[#409336] Rakefile Error - Please Help — "Jennifer T." <lists@...>

Hi,

13 messages 2013/08/04
[#409341] Re: Rakefile Error - Please Help — Hassan Schroeder <hassan.schroeder@...> 2013/08/04

On Sun, Aug 4, 2013 at 7:41 AM, Jennifer T. <lists@ruby-forum.com> wrote:

Re: Capture HTML table data, pass to Ruby, pass back and display result in HTML text field

From: Jes俍 Gabriel y Gal疣 <jgabrielygalan@...>
Date: 2013-08-04 13:54:19 UTC
List: ruby-talk #409334
On Sun, Aug 4, 2013 at 2:55 PM, Hubert Wagner <lists@ruby-forum.com> 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 =3D 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=92t see how the ERBs in Sub-Total/Grand Total could update
> the table once the page has been rendered.
>
> If item 1 above isn=92t 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=92t know where to begin with Ruby. (I=92=
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.

In This Thread