aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-12-14 23:13:53 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-12-19 14:43:26 +0000
commitc9f99c84d02856f742e8e99cc88cd5edd22313c3 (patch)
tree96fd7e235615d71493931f2bcab0549801569711 /perllib/FixMyStreet/App/Controller/Admin.pm
parent0fbacbf4108c2bbaff80a03fc45a6186c524fc9f (diff)
Area IDs come in as an arrayref, and body may not have an area ID.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm16
1 files changed, 11 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 651dd147d..d3b6a39ee 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -228,7 +228,9 @@ sub bodies : Path('bodies') : Args(0) {
my $params = $c->forward('body_params');
my $body = $c->model('DB::Body')->create( $params );
- foreach ($c->req->params->{area_ids}) {
+ my $area_ids = $c->req->params->{area_ids};
+ $area_ids = [ $area_ids ] unless ref $area_ids;
+ foreach (@$area_ids) {
$c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } );
}
@@ -362,7 +364,9 @@ sub update_contacts : Private {
$c->stash->{body}->update( $params );
my @current = $c->stash->{body}->body_areas->all;
my %current = map { $_->area_id => 1 } @current;
- foreach ($c->req->params->{area_ids}) {
+ my $area_ids = $c->req->params->{area_ids};
+ $area_ids = [ $area_ids ] unless ref $area_ids;
+ foreach (@$area_ids) {
$c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } );
delete $current{$_};
}
@@ -412,9 +416,11 @@ sub lookup_body : Private {
unless $body;
$c->stash->{body} = $body;
- my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id);
- if ($example_postcode && ! ref $example_postcode) {
- $c->stash->{example_pc} = $example_postcode;
+ if ($body->body_areas->first) {
+ my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id);
+ if ($example_postcode && ! ref $example_postcode) {
+ $c->stash->{example_pc} = $example_postcode;
+ }
}
return 1;