The small Massachusetts city is showing how investing in affordable housing, education, and job training can help power an economic recovery.