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 suppose the Sub-Total cells and the Grand Total cell would contain an
ERB : <% calculated value %>
However, I dont see how the ERBs in Sub-Total/Grand Total could update
the table once the page has been rendered.
If item 1 above isnt possible, the page could remain dormant until the
user clicks on a button to calculate the Grand Total.
I have the table. However, I dont know where to begin with Ruby. (Im
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.
-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.
Yes. Exactly.
I was assuming by using Ruby and ERB, I could interface with the HTML
Table directly.
Are you implying, by introducing JS, Ajex and DOM this is not possible?
I was assuming by using Ruby and ERB, I could interface with the HTML
Table directly.
Are you implying, by introducing JS, Ajex and DOM this is not possible?
Well, the Ruby web app executes in the server, while the user
interaction with the HTML happens in the browser.
You need some way to communicate between the browser and the server,
if you want the server side to do the calculations based on the user
interaction with the table.
-Well, the Ruby web app executes in the server, while the user
-interaction with the HTML happens in the browser.
-You need some way to communicate between the browser and the server,
-if you want the server side to do the calculations based on the user
-interaction with the table.
Communication with the server is unnecessary. The table on the page
allows a user to calculate a total cost based on his selections. This is
for his information only. He doesn’t order anything at this point.
So, I need to allow the user to check and uncheck checkboxes and add
quantities to the column D cells and then see the result.
Communication with the server is unnecessary. The table on the page
allows a user to calculate a total cost based on his selections. This is
for his information only. He doesn’t order anything at this point.
So, I need to allow the user to check and uncheck checkboxes and add
quantities to the column D cells and then see the result.
Then this is a JavaScript question and has nothing to do with Ruby.
Then this is a JavaScript question and has nothing to do with Ruby.
I use RubyFrontier. This allows one to use ERB on web pages produced by
RF.
So, an item like this :
<% ruby code %> is executed when the page is formatted.
Do I gather this is the only way Ruby can be made to work in a web page?
i.e. only at the moment the page is written out to HTML? Ruby routines
cannot be called directly from the web page?
Do I gather this is the only way Ruby can be made to work in a web page?
i.e. only at the moment the page is written out to HTML? Ruby routines
cannot be called directly from the web page?
That is the way RubyFrontier works (as I understand it)! A framework
like
Rails or Sinatra may
be used if you want to invoke Ruby routines through the server.
saji
Saji N Hameed,
ARC-ENV, Center for Advanced Information Science and Technology,
University of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushima 965-8580,
Japan
I’ve read the description about what is Ruby Frontier: it’s a static
web site generator. So, there’s no server side Ruby or anything, you
program in Ruby instructions about how to generate plain HTML, and
then you have to place them under a web server to serve them. So you
have HTML displayed in the browser, with no server side web app. So,
to do dynamic things with user interaction in a browser, all you need
is Javascript.