April 29 2009

Routing the Rails Way

Reference: http://www.informit.com/articles/article.aspx?p=1087656

If we’re speaking about route recognition, the bound parameters—key/value pairs in the hash of options at the end of the route’s argument list—determine what’s going to happen if and when this route matches an incoming URL. Let’s say someone requests this URL from their web browser:

http://localhost:3000/myrecipes/apples

This URL will match the ingredient route. The result will be that the show action of the recipes controller will be executed. To see why, look at the route again:

map.connect 'myrecipes/:ingredient',
            :controller => "recipes",
            :action => "show"

The :controller and :action keys are bound: This route, when matched by a URL, will always take the visitor to exactly that controller and that action. You’ll see techniques for matching controller and action based on wildcard matching shortly. In this example, though, there’s no wildcard involved. The controller and action are hard-coded.

Now, when you’re generating a URL for use in your code, you provide values for all the necessary bound parameters. That way, the routing system can do enough match-ups to find the route you want. (In fact, Rails will complain by raising an exception if you don’t supply enough values to satisfy a route.)

The parameters are usually bundled in a hash. For example, to generate a URL from the ingredient route, you’d do something like this:

<%= link_to "Recipe for apples",
   :controller => "recipes",
   :action     => "show",
   :ingredient => "apples" %>

The values “recipes” and “show” for :controller and :action will match the ingredient route, which contains the same values for the same parameters. That means that the pattern string in that route will serve as the template—the blueprint—for the generated URL.

The use of a hash to specify URL components is common to all the methods that produce URLs (link_to, redirect_to, form_for, etc.). Underneath, these methods are making their own calls to url_for, a lower-level URL generation method that we’ll talk about more a little further on.

We’ve left :ingredient hanging. It’s a wildcard component of the pattern string.

April 22 2009

What is DNS?

The Domain Name System (DNS) is a hierarchical naming system for computers, services, or any resource participating in the Internet. It associates various information with domain names assigned to such participants. Most importantly, it translates domain names meaningful to humans into the numerical (binary) identifiers associated with networking equipment for the purpose of locating and addressing these devices world-wide. An often used analogy to explain the Domain Name System is that it serves as the “phone book” for the Internet by translating human-friendly computer hostnames into IP addresses. For example, www.example.com translates to 208.77.188.166.

The Domain Name System makes it possible to assign domain names to groups of Internet users in a meaningful way, independent of each user’s physical location. Because of this, World-Wide Web (WWW) hyperlinks and Internet contact information can remain consistent and constant even if the current Internet routing arrangements change or the participant uses a mobile device. Internet domain names are easier to remember than IP addresses such as 208.77.188.166 (IPv4) or 2001:db8:1f70::999:de8:7648:6e8 (IPv6). People take advantage of this when they recite meaningful URLs and e-mail addresses without having to know how the machine will actually locate them.

The Domain Name System distributes the responsibility of assigning domain names and mapping those names to IP addresses by designating authoritative name servers for each domain. Authoritative name servers are assigned to be responsible for their particular domains, and in turn can assign other authoritative name servers for their sub-domains. This mechanism has made the DNS distributed, fault tolerant, and helped avoid the need for a single central register to be continually consulted and updated.

In general, the Domain Name System also stores other types of information, such as the list of mail servers that accept email for a given Internet domain. By providing a world-wide, distributed keyword-based redirection service, the Domain Name System is an essential component of the functionality of the Internet.

Other identifiers such as RFID tags, UPC codes, International characters in email addresses and host names, and a variety of other identifiers could all potentially utilize DNS [1].

The Domain Name System also defines the technical underpinnings of the functionality of this database service. For this purpose it defines the DNS protocol, a detailed specification of the data structures and communication exchanges used in DNS, as part of the Internet Protocol Suite (TCP/IP). The DNS protocol was developed and defined in the early 1980s and published by the Internet Engineering Task Force (cf. History).