What decides the shape of a galaxy? As I know, most galaxies are spiral, some elliptical, and a rare type is ring-shaped. 

What causes a galaxy to become a specific shape (i.e. ring vs spiral)?
The Hubble tuning fork classifies galaxies based on whether they are elliptical or have spiral arms, and whether there is or not a bar.



A historical aside

Edwin Hubble thought that galaxies started out as ellipses and evolved into spiral galaxies. This is why ellipticals are also called early-type galaxies, and spirals are spirals are called late-type galaxies.

As we studied galaxies more, we figured out that Hubble was wrong on that point, because elliptical galaxies typically have older stars and spiral galaxies still have new stars forming in them. 

Elliptical galaxies

In elliptical galaxies, the velocity dispersion of the stars is high: the stars have random orbits around the center of mass of the galaxy. This is seen to be evidence for the fact that elliptical galaxies are the result of collisions and mergers between many galaxies. 

When two non-elliptical galaxies merge, their planes are rarely aligned. So when many galaxies merge together, like what happened in the early universe, you end up with stars moving in many different directions. This is how a galaxy can end up being elliptical. 

Spiral galaxies

The spiral arms of a galaxy might come to be through two different mechanisms. It is possible that some spiral arms are caused by the first mechanism, and others by the second.

First mechanism: The arms of a galaxy are density waves.

Picture a traffic jam: all the cars are slowed down on a portion of the highway, but the cars that are in the jam aren't always the same ones. Each car reaches the traffic jam, slows down, gets to the end of the jam and speeds back up. This is what the stars are doing in the spiral arms: a star reaches the arm, slows down because of the higher density, gets to the end of the arm, resumes its normal speed. As a result, the arms spin slower than the individual stars. 

Second mechanism: The arms appear as star formation propagates through the galaxy.

The leading edge of the arm is where star formation occurs. The trailing edge is where stars die (so are no longer visible). In this case, there is not more matter in the arms, it simply is more visible. 

As stars form in one region, the largest ones cause shock waves to spread through the interstellar medium, igniting the formation of new stars. This causes the star-forming region to propagate through the galaxy. Combined with the differential rotation of the galaxy, this makes spiral arms appear. 

Other shapes

You mention ring galaxies in your question. These are possibly due to one galaxy having gone right through another. 

Many galaxies have bizarre shapes (e.g. the Antenna Galaxies) that are caused by interactions between galaxies.