Training, Open Source Programming Languages

This is page http://www.wellho.net/mouth/3773_Rub ... g-CGI.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Ruby on the web - a simple example using CGI

I've added a CGI example in Ruby - as part of the Ruby training I was doing yesterday. Source code is [here] to show how it works / "Proof of concept". In practise, I would use the cgi module in Ruby if I was doing server side work using CGI - "Hello World" using that module is [here], or if the application was much more than trivial I would use a framework such as Ruby on Rails.

Form inputs (using the default GET method) are delivered in the QUERY_STRING variable in the environment. They take the form of a series of & separated name=value pairs, which I separate out into a hash. The I have decoded the values further, as they may contain + characters for spaces, and % followed by two hex digits for other special characters. In theory, the names could be encoded in a similar way if my web page designer used special characters or spaces in field names. Also in theory, I could have multiple filed with the same name!

I have applied a further set of check on the contents of the field called search. This is done to ensure only simple literal searches to our web site visitor are offered, rather than allowing him to enter regular expressions. Of course, we're also removing the ability to search for special characters, but in a demonstration that's not really an issue.

When I echo out the value that was entered because it contains illegal search characters, I have to encode characters which mean something special to the browser within the HTML stream = & and <. In a full application I would do this on every output; in this sample, I've not done it on the data that I read from the file (as I know my data file won't change and is clean) nor on my correcly-echoed search string as I've already filtered that.

(written 2012-06-22, updated 2012-06-23)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
R114 - Ruby on the Web
  [1891] Ruby to access web services - (2008-11-16)
  [2605] Ruby on Rails - a sample application to teach you how - (2010-01-30)
  [2607] Answers on Ruby on Rails - (2010-01-30)
  [3431] Ruby at both extremes of your website - (2011-09-10)
  [3432] 3 digit HTTP status codes - what are they, which are most common, which should be a concern? - (2011-09-11)
  [3623] Some TestWise examples - helping use Ruby code to check your web site operation - (2012-02-24)
  [4003] Web and console - same principle, same code - Ruby example - (2013-02-14)
  [4502] Reading and parsing a JSON object in Ruby - (2015-06-01)


Back to
Hello World - Ruby on Rails - a checklist of each step
Previous and next
or
Horse's mouth home
Forward to
Melksham - a new dawn
Some other Articles
Multiple views in a single appication - sharing common parts of the template - Ruby on Rails
Some traps it's so easy to fall into in designing your web site
Alan Turing - 1912 to 1954
Melksham - a new dawn
Ruby on the web - a simple example using CGI
Hello World - Ruby on Rails - a checklist of each step
Fine evening, country walk from Melksham - pictures
Sample answers to training course exercises - available on our web site
Muttable v immutable and implications - Ruby
Melksham Chamber of Commerce - looking to our future shape. Pivotal meeting next Tuesday
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3773_Rub ... g-CGI.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb