[jifty-devel] How to delete a record through an action
Jesse Vincent
jesse at bestpractical.com
Fri Feb 15 14:45:05 EST 2008
On Feb 15, 2008, at 10:43 AM, Stanislav Sinyagin 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.
>
> 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:
>
I believe you need to specify the id as you instantiate the delete
action.
For kicks, can you try
my $del_action = $request->as_delete_action;
?
>
>
>
> 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,
> 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
>
More information about the jifty-devel
mailing list