This is one of the areas where even the modern Supreme Court is ahead of elected officials. The court has helped curb the worst of these abuses, starting with the ruling mandating that districts for the House of Representatives and state legislatures must all contain roughly the same population. Previously, one district might have one million people while the district next door would have 100,000.
Courts have also taken on partisan and racial gerrymandering with mixed success. While the Supreme Court has held since 1986 that partisan gerrymandering is unconstitutional, it has failed to find a standard to apply to specific maps – though hopefully that is changing. Courts have also thrown out districts drawn to dilute the impact of racial group and it seems like they may be close to taking on partisan gerrymandering.
However, this may take years and and its unlikely the courts will be able to prevent all types of gerrymandering.