Ruby-on-Rails
  Home arrow Ruby-on-Rails arrow Ruby for the Newbie
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
RUBY-ON-RAILS

Ruby for the Newbie
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-10-15

    Table of Contents:
  • Ruby for the Newbie
  • A Few Notes About Formatting
  • Variables
  • Constants

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Ruby for the Newbie


    (Page 1 of 4 )

    In last week's article, we installed Ruby on Rails the easy way, by first installing Ruby, then installing Rails. In this article, the second part of a six-part series, we'll actually do something with what we installed. We'll start with an offbeat version of the Hello World program, and move forward from there.

    In the bleak beginnings of 1999, three people -- Jason Fried, Carlos Segura, and Ernest Kim -- sat twiddling their thumbs and watching the night sky. All armed with shortwave satellites, they dutifully listened for extra-planetary sounds. As they shivered in the cold wind, they heard a small blip, and then another. Eventually the blip changed to static and the static changed to a voice: If you build it, nerds will come.

    The trio looked at each other in awe. For months they had been listening for the 37 radio telescope signals hailed by famed astrologer, Paul Horowitz, as being the most likely source for messages from extraterrestrials. And so they listened intently as other-worldly creatures went in depth on how to create Ruby on Rails web applications.

    And when they finished building the web application framework, one thing happened: nerds did come.

    At least that is how my imagination plays the scene (only in my head the nerds that come all have glowing fingertips as they type on their keyboards and mutter ouccccch.) In reality it probably occurred a little differently, although the trio did invent Ruby on Rails after creating their company 37signals (which really was named for Paul Horowitz's 37 radio telescope signals).

    In this tutorial, I will teach you the basics of programming with Ruby on Rails. I will make several assumptions:


    • You have Ruby on Rails installed and configured.

    • You have a database system installed, such as MySQL.

    • You have a .text editor such as Notepad.

    If you answered no to any of those, put this tutorial down and get to installing. If you answered yes, then feel free to read ahead...

    Jumping Right In

    If you have ever read a programming tutorial before, you know that writers like to use the Hello World Program as the first program you develop. In reverence to our brave and intrepid Ruby on Rails creators, we are going to write a program that mimics the conversation an alien will like have with us upon first contact.


    puts "Greeting Earthlings. Before you take us to your leader...

    puts "Take us to your restroom." # prints the text to the monitor


    This will display the text: "Greetings Earthlings. Before you take us to your leader...Take us to your restroom." on your monitor.

    Yes, that is a good example of what the aliens will say to us. I mean, they traveled across an entire galaxy to meet with us. The puts command tells the program to literally put your text on the screen. Simple as pie, right?

    What about numbers you say? What if aliens come but they only speak in binary? That too is simple:


    puts 01001101101001 # prints the numbers onto the monitor

    As you can see there is no difference between the two. You may however notice that I wrote # prints the numbers onto the monitor. In Ruby, you can leave comments for other programmers or yourself to refer to in case you ever have to go back and touch up your program. You do so by using the # symbol. When the computer sees this symbol, it ignores everything after it.

    More Ruby-on-Rails Articles
    More By James Payne


       · Before I comment, I just want to give you guys a brief heads-up: For some reason the...
       · Great article, James Payne "Gorilla Lord!" :)A couple of suggestions:1) This...
       · Hi Farsheed,Thanks for the comments. The sites are presently being redesigned,...
       · Well frankly, I have absolutely no idea how or where to begin. I'm more of a...
       · Hey! I finally found a solution to my problem regarding working in Shell and...
       · Hey Farsheed,Thanks for posting the solution. I have to agree with you regarding...
       · Hello James!As you can probably see, I finally created an account! I figured it...
     

    RUBY-ON-RAILS ARTICLES

    - Iterating and Incrementing Strings in Ruby
    - Comparing and Manipulating Strings in Ruby
    - Strings in Ruby
    - Ruby On Rails: Making Your First Dynamic Site
    - Ruby on Rails: Beginning Rails
    - Ruby: Modules, Mixins, Fixins, and Rails
    - Controlling Information Access with the Rail...
    - URLs, Filters and the Rails Action Controller
    - Flash and the Rails Action Controller
    - Rails Action Controller
    - Dropping and Sorting with AJAX and script.ac...
    - Drag and Drop with script.aculo.us and Rails
    - Introducing script.aculo.us
    - Ruby Classes and Objects
    - Ruby Loops







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT