I consider the routing support on MR one of its weaknesses. I wish
there was a way to bind a routing rule to the urlbuilder, so that
whenever a url routing rule is changed, it affects redirects and links
generated by the urlhelper (directly or indirectly)
Long time ago I spent some time on this, but the only way I found was
to give more semantics to the routing rule
/products/view/[id]
$Url.Link("view detail", { controller: product, action: view, id:
$product.id } )
Things can get really hairy if you're dealing with a "recursive" path
/products/[category]/.../[subcategory_n]/[productname]
$Url.Link("view detail", { ??? )
Any ideas?
--
Cheers,
hamilton verissimo
ham...@castlestronghold.com
http://www.castlestronghold.com/
I like that in MR :) We don't force our power-users to study and try
to hack into our "smart" code, they can replace any functionality for
their own.
> On 10/5/07, Hamilton Verissimo < ham...@castlestronghold.com> wrote:
> > Long time ago I spent some time on this, but the only way I found was
> > to give more semantics to the routing rule
> >
> > /products/view/[id]
> >
> > $Url.Link("view detail", { controller: product, action: view, id:
> > $product.id } )
Personally, I started to work with named capture groups on my routing
rules. So instead of:
<pattern>/product/(\d+)/show</pattern>
<replace>/product/show.rails?id=$1&</replace>
I'm using:
<pattern><![CDATA[ /product/(?<id>\d+)/show ]]></pattern>
<replace><![CDATA[ /product/show.rails?id=${id}& ]]></replace>
That makes it easier to inspect the rule and discover its parameter
names. We can also apply names and scopes to the <pattern> tag, for
use with the UrlHelper:
<rule name="showProduct">
<pattern><![CDATA[ /product/(?<id>\d+)/show ]]></pattern>
<replace><![CDATA[ /product/show.rails?id=${id}& ]]></replace>
</rule>
$Url.Link("view detail", { named: "showProduct", id: $product.id } )
<rule name="show" in-controller="product">
<pattern><![CDATA[ /product/(?<id>\d+)/show ]]></pattern>
<replace><![CDATA[ /product/show.rails?id=${id}& ]]></replace>
</rule>
<rule name="show" in-controller="user">
<pattern><![CDATA[ /restricted/user/(?<id>\d+)/show ]]></pattern>
<replace><![CDATA[ /restricted/user/show.rails?id=${id}& ]]></replace>
</rule>
When writing a view for ProductController:
$Url.Link("show product", { named: "show", id: $product.id } )
When writing a view for UserController:
$Url.Link("show user", { named: "show", id: $user.id } )
--
Fábio David Batista
fabio.dav...@gmail.com
http://nerd-o-matic.blogspot.com
On 10/5/07, Ayende Rahien <aye...@ayende.com> wrote:
--
Rafael Teixeira
Castle Stronghold