Difference between revisions of "Emergent Web Technologies Spring 2009 Class 6"

esse quam videri
Jump to: navigation, search
Line 3: Line 3:
 
This week we'll finish up with an introduction to Ruby and move on to Ruby on Rails. We'll start with an introduction to web frameworks in general, and then move on to [http://en.wikipedia.org/wiki/Model_view_controller Model View Controller]. Finally, we'll build a small Rails app in class to demonstrate how much more quickly you can build applications if you have a framework to start with.
 
This week we'll finish up with an introduction to Ruby and move on to Ruby on Rails. We'll start with an introduction to web frameworks in general, and then move on to [http://en.wikipedia.org/wiki/Model_view_controller Model View Controller]. Finally, we'll build a small Rails app in class to demonstrate how much more quickly you can build applications if you have a framework to start with.
  
 +
== In Class Activity 1 ==
  
== Commands to Run Before Developing ==
+
Develop a simple Ruby class that represents a Vehicle. The Vehicle class should have public properties for a registration id and a color. It should also have functions for starting and stopping the vehicle. Make the functions write "started" and "stopped" to the console when the car is started or stopped.
 +
 
 +
Develop a Car class that inherits from the vehicle class. The Car class should have a new public property for the number of doors. You should should be able to pass in the color and number of doors to the constructor for the car.
 +
 
 +
Once you have both of the classes created, test out your code by creating a new car and make sure that you can start it and stop it. Also, make sure that you can set the registration id and read back the color and number of doors by printing them out to the console.
 +
 
 +
Your test code should look something like this
 +
 
 +
car = Car.new(4, :green)
 +
car.registration_id = 5000
 +
 
 +
puts car.registration_id
 +
puts car.color
 +
puts car.number_of_doors
 +
 
 +
Remember that a Ruby class looks like this
 +
 
 +
class Vehicle
 +
 
 +
end
 +
 
 +
== Commands to Run Before Developing With Rails ==
  
 
Before you start developing with Ruby on Rails, you'll want to make sure that all of the code associated with Rails is current. These commands will make sure that everything is up to date with the latest versions.
 
Before you start developing with Ruby on Rails, you'll want to make sure that all of the code associated with Rails is current. These commands will make sure that everything is up to date with the latest versions.

Revision as of 21:58, 4 March 2009

Introduction

This week we'll finish up with an introduction to Ruby and move on to Ruby on Rails. We'll start with an introduction to web frameworks in general, and then move on to Model View Controller. Finally, we'll build a small Rails app in class to demonstrate how much more quickly you can build applications if you have a framework to start with.

In Class Activity 1

Develop a simple Ruby class that represents a Vehicle. The Vehicle class should have public properties for a registration id and a color. It should also have functions for starting and stopping the vehicle. Make the functions write "started" and "stopped" to the console when the car is started or stopped.

Develop a Car class that inherits from the vehicle class. The Car class should have a new public property for the number of doors. You should should be able to pass in the color and number of doors to the constructor for the car.

Once you have both of the classes created, test out your code by creating a new car and make sure that you can start it and stop it. Also, make sure that you can set the registration id and read back the color and number of doors by printing them out to the console.

Your test code should look something like this

car = Car.new(4, :green)
car.registration_id = 5000
puts car.registration_id
puts car.color
puts car.number_of_doors

Remember that a Ruby class looks like this

class Vehicle
  
end

Commands to Run Before Developing With Rails

Before you start developing with Ruby on Rails, you'll want to make sure that all of the code associated with Rails is current. These commands will make sure that everything is up to date with the latest versions.

Open the Instant Rails application and right click on the icon in the taskbar. Choose Rails Applications > Open Ruby Console Window. Run this command first

gem install rubygems-update

Once the first command has completed, run this command

update_rubygems

Finally, run this command

gem update rails

You should now be up to date.