Home arrow Ruby-on-Rails arrow Ruby for the Newbie
RUBY-ON-RAILS

Ruby for the Newbie


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.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
October 15, 2007
TABLE OF CONTENTS:
  1. · Ruby for the Newbie
  2. · A Few Notes About Formatting
  3. · Variables
  4. · Constants

print this article
SEARCH DEVARTICLES

Ruby for the Newbie
(Page 1 of 4 )

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.


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials