Is it OK to use foam for the ribs of an ultralight's wing?
The foam is used to take small shearloads and support the primary structural element in absorbing tension and compression loads.  The wood rib has the primary compression and tension members in the capstrip, with the diagonals absorbing shear loads, converted to compression and tension loads along the legs of the truss. On a foam rib, if it is a standalone rib not connecting to a stressed skin, you need to have a structural capstrip material, like wood or fibreglass because the foam only has strength when the loads are distributed over a large area.  The foam itself does the job of the diagonal members in holding the caps in place and absorbing shear forces in the rib.  Some ultralights have a foam rib core with an aluminum cap strip bonded to the edges to do this.  

If the foam rib is inside a stressed skin wing, the stressed skin is effectively the cap strip and the foam can be bonded directly to it.  Because the foam isn't very strong it requires a large number of foam ribs, closely spaced to properly support the stressed skin.