Home arrow Ruby-on-Rails arrow Page 3 - Ruby on Rails: Beginning Rails
RUBY-ON-RAILS

Ruby on Rails: Beginning Rails


In our last article I left you with a cliffhanger -- you learned to create a third of your first web application with Rails. If you are back here reading this article then my evil plot worked. In this episode we will continue building our first application in Rails and learn to create a basic skeletal framework.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
April 28, 2008
TABLE OF CONTENTS:
  1. · Ruby on Rails: Beginning Rails
  2. · Controlling the Situation
  3. · A View...To a Kill (Duhn Duhn Dun!!!)
  4. · What Everything is For

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Ruby on Rails: Beginning Rails - A View...To a Kill (Duhn Duhn Dun!!!)
(Page 3 of 4 )

That's right folks, articles with sound effects. I'll be here all week.

So far we have created a controller and an action, which handle requests from the user and respond to the requests, respectively. Now, with our view, we will display said results to the user.

In order to do so, we create what is called a skeleton or a template web page whose ultimate purpose is to display something to the user. Actions use templates to store and display information, as you will soon see.

Templates are named with the .rhtml extension. If you name them the same as the action, they are instantly connected. So, in our case, we will name our template file whatyoutalkingbout.rhtml.

Creating our View

Open up a text file and enter in this brilliant code:


<html>

<body>

<h2>Welcome to the What You Talking About Website</h2>

<br>

<p>Here we will discuss what things Willis could have possibly been talking about, and furthermore, why Arnold was so damned anxious to find out...</p>

</body>

</html>

Go ahead and save the file in the rubymyfirsttimeappviewswillis folder.

Now start your WEBrick server again, as shown above. And finally, open up a browser and go to http://localhost:3000/willis/whatyoutalkingbout

You should see the text:

  Welcome to the What You Talking About Website

  Here we will discuss what things Willis could have possibly been talking about, and furthermore, why Arnold was so damned anxious to find out...

Congratulations on your first Rails web application.

How it all Works

When the user enters a URL, a request is sent to your web server, which is then decoded and sent to your controller. The controller then calls upon the actions that you create and passes the request on to the appropriate action. The action is determined by the URL. In our example, the action displayed a template with some data. Whoopee!


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 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials