[Catalyst] OT: edit/add seperate actions?

J. Shirley jshirley at gmail.com
Tue Mar 3 18:09:24 GMT 2009


On Tue, Mar 3, 2009 at 8:53 AM, Mark Trostler <mark at zzo.com> wrote:

> Iain wrote:
>
>> Hello all,
>>
>> So we are having a discussion @work about basic add/edit functions. We
>> currently have currently two lines of thoughts on handling it.
>>
>> 1. Have separate actions for adding and editing e.g.
>>
>> # add
>> /app/notice/add_new (POST To) /app/notice/process_add_new
>>
>> # edit
>> /app/notice/*/edit (POST To) /app/notice/*/process_edit
>>
>> 2. Have a shared edit action with an if ( $c->req->method eq 'POST' )
>> check.
>>
>> # edit
>> /app/notice/*/edit (POST Back to) /app/notice/*/edit
>>
>> There currently doesn't look like much difference in lines of code to
>> manage.
>> Just wondering if anybody has any thoughts/experience, pros/cons best
>> practice etc of either approach.
>>
>> Actually, I like option 2 best. So I suppose I'm asking for reasons why
>> we shouldn't use option 1 :-)
>>
>>
> If you're using Javascript for your forms you're 95% of the way to
> Catalyst::Controller::REST.  POST =3D create, PUT =3D edit, GET & DELETE =
work
> out great...  A much cleaner solution IMHO.
>        Mark
>
>
All Grade-A browsers currently support GET, PUT, POST and DELETE as the
request method via XmlHttpRequest.  You are limited to same-domain requests,
etc.

It's a very good solution, and works well.  I employ this method a lot with
REST.

Having said all that, you really must be sure to degrade gracefully or
account for failures and accessibility.  One method I use is links
constructed like: <a href=3D"[% delete_link %]" class=3D"rest-delete">Delete
Me!</a>

Then use JS to detect that link (either by bubbling or whatever) and then
hijack those link clicks and send them via an asynchronous javascript call.

The degrading experience is great, because the delete_link will get followed
if the JS fails to execute.

-J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090303/d8893=
5ec/attachment.htm


More information about the Catalyst mailing list