Ruby On Rails: Making Your First Dynamic Site - Creating Two Views and Choosing Between Them
(Page 3 of 4 )
The problem with Views (and women) is that you can only have one at a time. Well that's not entirely true I guess. But with views it is. Wait where am I?
In this example we are going to create two...no wait...three views and then choose between them. Or at least we are going to say we chose one of them, when we are really just going to visit each one at certain times intervals during the day. You sly dog you.
For this example we are going to start anew. First create a new application and name it timeclock.
>rails timeclock
Now change your directory to the timeclock and create a new controller named Decision.
>cd timeclock
>ruby script/generate controller Decision
Next we are going to add three actions to our Decision.rb controller. Open it up and add the following code so it reads like this:
class DecisionController < ApplicationController
def start
end
def lunch
end
def home
end
end
Now open up Notepad and create three separate files named Start.rhtml, Lunch.rhtml, and Home.rhtml respectively. Here is the code for each one:
For Start.rhtml:
<html>
<body>
<h1>Get to work slave!</h1>
</body>
</html>
For Lunch.rhtml:
<html>
<body>
<h1>Lunch time! But only bread and water for you!</h1>
</body>
</html>
For Home.rhtml:
<html>
<body>
<h1>You can go home, but you better dream about this place or else!</h1>
</body>
</html>
If you want to, you can test each view now by turning on your WEBrick server and going to
http://localhost:3000/decision/start
or
http://localhost:3000/decision/lunch
or
http://localhost:3000/decision/home
Next: Choosing Which View to View >>
More Ruby-on-Rails Articles
More By James Payne