Home arrow Ruby-on-Rails arrow Page 2 - 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 - Controlling the Situation
(Page 2 of 4 )

To make an application work, you first need a controller. The controller is the evil overseer, the big boss, the big cheese, the head honcho, the imperial slave-driver. He is that guy that says "I think the benefits of slavery outweigh its drawbacks" and then makes you carry heavy boulders back and forth.

To create this big galoot we use the following ruby command: ruby script/generate controller controllername. Below we will create a controller named Willis, in the hopes of later learning what the heck he was talking about:


ruby script/generate controller Willis

If you go to rubymyfirsttimeappcontrollers you will see a file name willis_controller.rb. This is the file you just created. You can open it to view the code if you like; just be sure not to change it.

A Call to Action

While having a controller is all fine and dandy, it's pretty worthless if it isn't issuing orders for its minions to follow. This is where Actions come in. Actions are what make your application do things. The following action will make the browser display some text. Here is how you add your action to the controller:

Open the myfirsttime.rb controller file. It will show the text:


class WillisController < ApplicationController
end

We are going to insert some text in-betwixt the first line and the end line:


def whatyoutalkingbout

end

This creates a method called whatyoutalkingabout. Typically you would use something simpler, but I wanted to match the theme. And it's my article, so there. So now the file should read:


class WillisController < ApplicationController

def whatyoutalkingbout

end

end

And lastly, in order to complete our beautiful web page, we must create a View.


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