Skip to content

Instantly share code, notes, and snippets.

@tudorconstantin
Created August 15, 2012 11:35
Show Gist options
  • Save tudorconstantin/3359395 to your computer and use it in GitHub Desktop.
Save tudorconstantin/3359395 to your computer and use it in GitHub Desktop.
generic REST update with Mojolicious and DBIx::Class
sub update{
my $self = shift;
my $result_rs = $self->app->model
->resultset( $self->{resource} )
->search_rs(
{ id => $self->param('id') },
);
return $self->render_not_found if ( scalar( ( $result_rs->all ) ) == 0 );
$result_rs->update_all( $self->{_payload} );
$result_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
my @result = $result_rs->all();
return $self->render_json( @result );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment