[jifty-devel] How to delete a record through an action

Andrew Hanenkamp sterling at hanenkamp.com
Fri Feb 15 20:52:42 EST 2008


On 2/15/08, Stanislav Sinyagin <ssinyagin at yahoo.com> wrote:
>
> I'm a bit stuck with the use of Actions.
>
> I want to list the records in a table, and at the end of each row place
> a link "Delete" which would delete the record.


I think Jesse's suggestion may work, but I have another.

The code follows. When I click "Delete", the debug log says the
> corresponding
> action is found, but when the Model object's "delete" method is called,
> it's called in an object that was not loaded from the database, and
> therefore
> its ID is unknown, and basically the deletion is not happening:
>
>
>
>
>     my $requests = new Toponet::Model::TraceRequestCollection
>         (current_user => Jifty->web->current_user());
>
>     $requests->limit( column    => 'startDevice',
>                       operator  => '=',
>                       value     => $deviceID );
>     my $reqs = $requests->items_array_ref();
>
>     if( scalar(@{$reqs}) > 0 )
>     {
>         my $delAction = Jifty->web->new_action
>             (class => 'Toponet::Action::DeleteTraceRequest',
>              moniker => 'delete_trace_request');
>
> </%perl>
>      <P>Existing trace requests:</P>
>      <TABLE>
>      <TR>
>        <TH>Request ID</TH>
>        <TH>Submitted</TH>
>        <TH>Status</TH>
>        <TH>Target IP</TH>
>        <TH>Completed</TH>
>        <TH>Results</TH>
>        <TH>Action</TH>
>      </TR>
>
> %       foreach my $request
> %           (sort {$a->id() <=> $b->id()} @{$reqs}) {
>
>      <TR>
>        <TD><% $request->id() %></TD>
>        <TD><% scalar(localtime( $request->timeCreated() )) %></TD>
>        <TD><% $request->status() %></TD>
>        <TD><% $request->targetValue() %></TD>
>        <TD><% $request->status() eq 'complete' ?
>                 scalar(localtime( $request->timeComplete() )) : '' %></TD>
>        <TD><% $request->status() eq 'complete' ?
>                '<A HREF="/show_trace_results.html?traceID=' .
> $request->id() .
>                '">view</A>' : '' |n %></TD>
>        <TD>
>        <% Jifty->web->form->start %>
>        <% Jifty->web->link
>        (label  => 'Delete',
>         as_link => 1,
>         onclick => {
>             submit => $delAction,


Replace the line above with:

  submit => { action => $delAction, arguments => { id => $request->id(), },
},

and drop the line below starting with "args => ".

            args => { id => $request->id() },
>             refresh_self => 1 }) %></TD>
>        <% Jifty->web->form->end %>
>      </TR>
>
> %       }
>      </TABLE>
> %    }
>
>
>
>
>
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jifty.org/pipermail/jifty-devel/attachments/20080215/f92d9f9c/attachment.htm 


More information about the jifty-devel mailing list