Home arrow Ruby-on-Rails arrow Page 3 - Ruby On Rails: Making Your First Dynamic Site
RUBY-ON-RAILS

Ruby On Rails: Making Your First Dynamic Site


In our last article we learned how to create a static web page with Rails and learned all about the workings of the grand Model-View-Controller architecture. In this article I am going to teach you how to create dynamic pages using Rails as your framework.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
May 05, 2008
TABLE OF CONTENTS:
  1. · Ruby On Rails: Making Your First Dynamic Site
  2. · Viewing Your Page
  3. · Creating Two Views and Choosing Between Them
  4. · Choosing Which View to View

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- 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
- Ruby on Rails Templates and Layouts
- Action Pack Controller Creation
- Writing an Action Pack Controller

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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