cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@d-haven.org>
Subject Further clarification about the CRACK type resource resolution
Date Tue, 11 Oct 2005 21:14:58 GMT
I did some further reading from my "Agile Web Development with Rails" 
book, and found out that while the normal idiom supported by Rails is as 
I originally specified, it is relatively easy to modify.

All the routing is specified in the conf/Routes.rb class.  The Routes.rb 
class does a simple mapping of request URL to some request variables.  
These request variables include :controller and :action to map to the 
controller class and the action method respectively.  You can override 
this default mapping.  The process is to override the 
Routing.Routes.draw static method to add the different route mappings.  
The defaults here are:

map.connect ':controller/service.wsdl', :action => 'wsdl'
map.connect ':controller/:action/:id', :defaults => { :action => 
"index", :id => nul }

Essentially, the first parameter has the names of the map entries (the 
items with ':' in front) that match the item in the URL prototype, 
followed by any additional names we want to set up.  The defaults map 
entry which in turn holds another map of entries that will be used if 
there is no match.  For example, with these wiring approaches the 
following will be true:

URL: foo/service.wsdl
maps to: controller = "foo_controller", action = "wsdl"

URL: bar
maps to: controller = "bar_controller", action = "index", id = nil

URL: bar/baz
maps to: controller = "bar_controller", action = "baz", id = nul

URL: bar/baz/1
maps to: controller = "bar_controller", action = "baz", id = 1

This is actually not a bad approach.  Essentially you get some fancy URL 
rewriting that sets up your environment for you.  There are two required 
entries for any wiring to work which are the controller and the action.  
Everything else is ad-hoc, although the id is an encouraged (and in many 
cases expected) idiom.

We are not limited to the defaults either.  We have the ability to 
specify regular expressions to validate URL bits.

The additional item here is more of a Ruby idiom in that the ":name" 
approach is that we are specifying a symbol which is a predefined 
object.  It would be analogous to us specifying some enumerations for 
the entries in the router.

All that I am putting forth here is that this is a mechanism that can be 
powerful to extend and use for our own purposes.


Mime
View raw message