[Catalyst] Relative links

Marcello m.romani at spinsoft.it
Thu Nov 10 11:06:28 CET 2005


Andreas Marienborg ha scritto:
> 
> On 10. nov. 2005, at 09.33, Marcello wrote:
> 
>> Bill Moseley ha scritto:
>>
>>> Relative links are biting me again, so I'm wondering how others
>>> generate links in a sane way.
>>> I have an action /admim/things that displays a table of rows.  I have
>>> some common template code for displaying tables that include column
>>> headings that can be clicked on for sorting by that column.  For  those
>>> headings I use relative links so the template code is portable:
>>>     <th><a href="?o=date">Date</a></th>
>>>     <th><a href="?o=name">Name</a></th>
>>> That works great, in general.  Plus, it allows any additional
>>> arguments to be included in the links.  (e.g. /admin/things/blue  might
>>> limit to just the blue things, so the sort would be
>>> /admin/things/blue?o=date).
>>> But that same feature causes trouble when forwarding from another
>>> action.
>>> An example might be where I re-show the list after deleting an item:
>>>     package App::C::Admin::Thing;
>>>     sub delete {
>>>         my ($self, $c, $id ) = @_;
>>>         DB::Thing->retrieve($id)->delete;
>>>         $c->stash->{message} = "Thingy $id was deleted";
>>>         $c->forward('/admin/things');  # App::C::Admin::things() :  
>>> Local
>>>     }
>>> Then the relative links on the table end up like this, of course:
>>>     /admin/thing/delete/234?o=date
>>> instead of:
>>>     /admin/things?o=date
>>> I can't use $c->req->action or $c->req->match as that's the action
>>> that matched the original request (/admin/thing/delete/234).  I
>>> suppose I could redirect, but that's very ugly.
>>
>>
>> But if you don't redirect the user will see /admin/thing/delete/234  
>> while the page displays a listing of things.
>> If she presses the reload button after deleting something, the  action 
>> that gets replayed is not the listing but the deletion,  probably 
>> bringing her to an error page because the item with the  displayed id 
>> doesn't exist anymore (it's just been deleted).
>>
>> This is my experience and why I redirect after a deletion.
>>
>> But I agree that redirecting is quite ugly (not to mention slooow).
> 
> 
> 
> Another way is of course to use XMLHttpRequest (ajax) for the  deletion, 
> and just display a small throbber that will be hidden on  onSuccess, and 
> display a error in the onError.

That's the Cool Way(TM) of doing things these days... ;-)

> 
> I am doing that right now actually, although for autosaving formfields.
> 
> andreas
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
> 


-- 
Marcello Romani
Developer
Spin s.r.l.
Reggio Emilia
http://www.spinsoft.it




More information about the Catalyst mailing list