Ruby-on-Rails
  Home arrow Ruby-on-Rails arrow Page 3 - Ruby On Rails: Making Your First Dynamic S...
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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
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 On Rails: Making Your First Dynamic Site
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2008-05-05

    Table of Contents:
  • Ruby On Rails: Making Your First Dynamic Site
  • Viewing Your Page
  • Creating Two Views and Choosing Between Them
  • Choosing Which View to View

  • 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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    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

    More Ruby-on-Rails Articles
    More By James Payne


       · Thanks for stopping by to read another episode in my series on Ruby on Rails. Here...
     

    RUBY-ON-RAILS ARTICLES

    - 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
    - Ruby Conditionals
    - Ruby Operators and Arrays
    - Ruby for the Newbie


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway