4

In my HTML page, I simply have an input box and an output box.

The Ruby script 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?

5
  • I recommend html tutorial, so you could pick up basics. If you do know html already, then please tell what's the part in this task you've having difficulty with. Commented Apr 24, 2011 at 3:23
  • Are you using Ruby on Rails, or just Ruby on its own? Commented Apr 24, 2011 at 3:34
  • ...or Sinatra or CGI or Padrino or... Commented Apr 24, 2011 at 3:40
  • 2
    You'll either need to use some server-side setup with Rails or a simpler server-side library, or switch to Javascript (the easier solution). Commented Apr 24, 2011 at 3:54
  • "I'm just using Ruby", then how are you getting the value of the input box? Or, are you trying to spec out code you need written? Commented Apr 24, 2011 at 6:16

1 Answer 1

4

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.