So this has been an idea ever since Rails came out.  Why not use a  
pure regular expression router in similar fashion to gsub?  I imagine  
it working something like this:

Merb::Router.prepare do |r|
   r.add %r[^/(.*)/(.*)/(\d+)$], :controller => '\1', :action =>  
'\2', :id => '\3'
   r.add %r[^/user-(\d+)$], :user_id => '\1', :controller =>  
'free_area/users', :action => 'index'
end

The flexibility is endless in this system (far more possibilities  
than Rails' system) and it lets people immediately grasp routes if  
then understand regular expressions (which they should, otherwise,  
this is a good opportunity to learn).

In addition, I propose we add more options to the router so that the  
protocol, port, and domain become available:

   r.add :path => %r[^/([^\/,?]*)$], :domain => /^(blog|news) 
\./, :controller => '\1', :action => 'index'

Once this is set up, we could potentially add a convenience layer on  
top so that we get something a little more like our current routes:

r.add ":controller/:action"
# Detection of a string causes r.add to create a regexp route  
matching the string, e.g.:
# r.add %r[^/([^/,?]+)/([^/,?]+)], :controller => '\1', :action => '\2'

Thoughts?

Duane Johnson
(canadaduane)
_______________________________________________
Merb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/merb-devel

Reply via email to