ASP.NET's http pipeline vs. Rails' MVC model 8
The “pipeline” in ASP.NET (sometimes called the “web stack”) can be pretty difficult to understand at first. It’s this “pipeline” that explains how IIS receives a reques for a url and somehow calls your aspx code. Generally speaking, the url is for a specific .aspx page (if none is specified, IIS usually looks for Default.aspx), and then it calls a series of confusing methods in your page, like Page_Init(), Page_Load,() PreLoad(), PostPreInitPreLoad()... ok I made a few of those up, but it’s not at all obvious at first blush what ASP.NET is going to call and when. And I haven’t mentioned the nightmare of IsPostBack().
Compared to all that stuff, the object model in Rails is a breath of fresh air. Coming from a Microsoft-jargon background, here’s how I came to understand the “Rails pipeline” (I’m ignoring details of CGI or other server-specific technologies):
1. A url is mapped to a particular method of a class that you write.
Ta da! That’s all there is to know for 99% of the cases. Each time a url is entered in the browser, Rails will instantiate a class, and then call a method on that class.
Now, the question you might be wondering is, how does it know which class and which method I want it to call for a given url? The answer to that is called “routing” in Rails-speak. Just start by writing your class (the “controller”). Then write a public method that takes no parameters (the “action”):
class PicturesController < ApplicationController
def thumbnails
# retrieve thumbnails from database
@thumbnails = Picture.find_by_size("small")
end
end
In this case, the url to call the thumbnails method would be: http:///www.mysite.com/pictures/thumbnails.
Ok, wait, take a breath for a sec. Look at that url again. It’s almost – gasp – readable! No .aspx at the end, no .htm, no .html, no giving away what “page” is being called. Indeed, you don’t even have a folder called /pictures/thumbnails, as you would expect if this were an ASP application.
Instead, the url specifies the class and method you want to call. Crazy, huh?
Hold on, you say. There’s nothing in there that says what should be returned to the browser! You’re right. The last part is to create an rhtml file called views/pictures/thumbnails.rhtml, and add your HTML code which can contain embedded Ruby script which can access the @thumbnails array defined by the controller. You don’t have to write any code that says “when the PicturesController#thumbnails method is called, use thumbnails.rhtml to render the HTML”. Just follow the naming convention of where to put your .rhtml file and Rails will find it automatically.
But that’s a topic for another day.




Have you figured out how to do debugging steps? I can work on the breakpoint but have no idea how to step into the lines.
Each time a url is entered in the browser, Rails will instantiate a class, and then call a method on that class.
I think that's a bit confusing. Each time a URL is entered into the browser, Rails compares it to routes.rb , works out what you're asking for, and calls the appropriate method on the appropriate controller - as well as passing any other variables to the controller.
Sometimes, that'll make an instance variable from a class, and run a method on it - but not always. It is the case when you start out with a basic, scaffolded app, and is usually the case as you go on - but it doesn't have to be. It could just render a plain template, no classes involved, for instance.
I'm working!
Not really new!
Thanks :)
Kinda cool thanks for that!
The transcendental objects in space and time prove the validity of, in natural theology, pure reason.
As we have already seen, the reader should be careful to observe that the architectonic of human reason, by means of our knowledge, exists in space; with the sole exception of necessity, the thing in itself may not contradict itself, but it is still possible that it may be in contradiction with, thus, the Antinomies.