[Catalyst] OT: edit/add seperate actions?

Zbigniew Lukasiak zzbbyy at gmail.com
Tue Mar 3 20:53:08 GMT 2009


On Tue, Mar 3, 2009 at 7:33 PM, Peter Karman <peter at peknet.com> wrote:
> Iain wrote on 03/03/2009 09:33 AM:
>> 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.
>>
>
> CatalystX::CRUD::Controller does:
>
>  /app/notice/create   # redirect internally to 0/edit
>  /app/notice/*/edit   # POST to /app/notice/*/save
>
> The '0' placeholder indicates it is a new object. '0' has the nice
> effect of evaluating true for defined() and length() but false
> otherwise. OTOH, it means you can't have a valid OID that == 0.
>
> If you use CatalystX::CRUD::REST, you can do:
>
>    # POST      /foo                -> create new record
>    # GET       /foo                -> list all records
>    # PUT       /foo/<pk>           -> update record
>    # DELETE    /foo/<pk>           -> delete record
>    # GET       /foo/<pk>           -> view record
>    # GET       /foo/<pk>/edit_form -> edit record form
>    # GET       /foo/create_form    -> create record form
>
> CatalystX::CRUD::REST uses the C::R::REST::ForBrowsers feature of
> 'x-tunneled-method' param to support PUT and DELETE via POST.

And where do the forms submit?  I mean what is their action address?
Do they submit to themselves - or does edit_form submit to
/foo/<pk>?x-tunneled-method=PUT and create to /foo both with POST
method?  And it is the second - then what do you do when the form
parameters are incorrect and you need to redisplay the form?

--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/



More information about the Catalyst mailing list