Help inserting Ruby script in HTML
In my HTML page, I simply have an input box and an output box.
The Ruby sc开发者_开发问答ript I have simply extracts the value from the input box, calculates and needs to display the output in the output box.
How do I get this done in my HTML code?
Try using Ruby as your CGI back-end. Here is a simple overview of what Ruby with CGI might be. You can also delve into the intro given by the Pragmatic Programmers here. So fo example:
if your HTML contains a form that has the field someVal
,
then you can access it using Ruby's cgi as:
require 'cgi'
cgi = CGI.new
cgi['someVal'] » ["whatever they sent in someVal"]
To make it even more interesting, without using any special frameworks, you can use Ruby's eruby
so that you directly embed your Ruby in HTML :-).
Something like:
This text is <% a = 100; puts "#{a}% Live!" %>
Gives something like:
This text is 100% Live!
Try it out, I know you'll love what you learn...
精彩评论