What is tough in Java Servlets is Easy in Ruby / Rails

I am amazed at the flexibility of Rails. I needed a way to dispatch between the portal and a tool and communicate which “context” / “site” the tool is supposed to operate in.
In Sakai we have complex stuff like a request filter and obtuse code buried in portal to accomplish this.
In Ruby it is trivial…


In my portal’s view – I add this line:
<%= link_to_remote 'Users', :update=> ‘main-content’,
:url => { :action => ‘ajaxstart’, :controller=>’users’,
:div => ‘main-content’, :context => 1} %>
The context is the site id.
In my routes.rb file it looks like this:
map.connect ”, :controller => “portal”
map.connect ‘:controller/:context/:div/:action/:id.:format’
map.connect ‘:controller/:context/:div/:action/:id’
map.connect ‘:controller/:context/:div/:action’
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action’
Rails adds the context to the URL when the portal generates the link URL and when the application makes a url using the url_for helper – the context (and div) are pre-pended to every URL – with zero changes to the application.
the urls look like
/controller/site-id/div-name/action
Both the URL made by the portal and the url made by views in the tool.
Abstraction abstraction abstraction – lots of flexibiltiy – lots of power.