Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Writing a simple CGI in Ruby is easy, however, explaining how is beyond the scope of Stack Overflow. </p> <p>To start, read Wikipedia's <a href="http://en.wikipedia.org/wiki/Common_Gateway_Interface" rel="nofollow">Common Gateway Interface</a> article so you have a basic idea of what a CGI has to return. Pick apart the Perl example; You should be able to figure out what's going on easily enough. Read through the article and compare what it says to what the code example is doing. </p> <p>Next, look at Ruby's <a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/cgi/rdoc/CGI.html" rel="nofollow">CGI</a> module, because it will help you parse incoming form information, and encode/decode URLs and HTML. Look at the table of environment variables, and you'll see the same things passed in that are mentioned in the Wikipedia article. Next, notice the <code>params()</code> method, which is how you access form variables. Follow that by reading the "Writing output" and "Generating HTML" sections, and nose about in the examples. You should be on your way then.</p> <p>Once you've done that, you should take a look at the <a href="http://www.sinatrarb.com/" rel="nofollow">Sinatra</a> gem. It's a very nice, easy to use, framework that is well suited for general web use, and, after getting an understanding of how a CGI works, you'll be in a good place to appreciate what Sinatra does for you. Additionally, I highly recommend using <a href="http://haml.info/" rel="nofollow">HAML</a> with Sinatra. It's a short-cut language for generating web pages, similar to ERB, but less verbose.</p> <p>You'll find that PHP has shielded you from a lot of the knowledge needed to write a "normal" web application using a CGI. That's OK if you already know that stuff, but it's bad if you have never done lower-level code, or are trying to use different languages, because knowing the CGI layer provides a lot of knowledge that is needed to understand the whole HTTPD stack. Once you know the CGI layer, things like Sinatra, Rails, Django, Mojolicious and all the other frameworks out there suddenly make more sense, and you'll know when to take advantage of them or roll your own. And, PHP's place in the HTTP server will be clearer too, allowing you to pick and choose your tools better for the job at hand.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload