Building an application with Ruby on Rails - Controllers
What have I found out so far?
Technorati Tags: Building an application with Ruby on Rails - Controllers
Blogs linking to this article
- A simple understanding of Ruby programming language
- Getting started with Ruby on Rails
- The controllers subdirectory is where Rails looks to find controller classes. A controller handles a web request from the user.
- The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.
- The models subdirectory holds the classes that model and wrap the data stored in our application's database.
- The helpers subdirectory holds any helper classes used to assist the model, view, and controller classes. This helps to keep the the model, view, and controller code small, focused, and uncluttered.
- In the command window, go to folder C:\InstantRails\rails_apps\jauth
- To create a new controller class type in this command window - ruby script\generate controller MyTest. This creates a file named my_test_controller.rb containing a skeleton definition for the class MyTestController.
- Now type the url http://127.0.0.1:3000/my_test/ this displays Unknown action No action responded to index. The my_test part of the URL maps to the newly created controller. Now it seems that Rails tried to find an action named index in this controller but couldn't. Let's fix that.
- Add an index method (shown in the code below) to your controller class and then refresh your browser. However, we see an error Template is missing Missing template ./script/../config/../app/views/my_test/index.rhtml
- We shall remove this error temporarily, by creating a file index.rhtml (as shown below) in the folder C:\InstantRails\rails_apps\jauth\app\views\my_test
#my_test_controller.rband the file index.rhtml
class MyTestController < ApplicationController
def index
disp = 'Hello World'
end
end
<html>The MyTest controller class will not be used again in our application. In my next post, we shall look at Models, though we would re-visit Controllers again later.
<head><title>jauth Application</title></head>
</html>
First Post | Previous | Next
Technorati Tags: Building an application with Ruby on Rails - Controllers
Blogs linking to this article
1 Comments:
see this onjava article -
http://www.onjava.com/pub/a/onjava/2005/11/16/ruby-the-rival.html
-Manoj
Post a Comment
<< Home