Dogs may eat grass to purge their stomach, also if their stomach is empty, bile from the gall bladder still secretes into the stomach and hence they puke yellow bile, this doesnt happen when there is food in their stomach as the bile aids digestion.
Another reason why dogs eat grass is to lower or higher their rank, in most cases it is to lower their rank, when 2 dogs sniff each others face they are checking out their 'weaponry' ie the teeth and with their acute sense of smell they can determine what they have eaten, lower ranks have a less percentage of meat versus veg in their diet, so by eating grass would lower their rank immediately , they may do this when they can smell or sense a higher ranking animal in the area, you may see them sniff the ground and then go and eat some grass.
Sometimes they will do it to higher their rank, often this is when Fox pee is present in the grass, as foxes mainly have a meat diet this would higher the dogs rank when another dogs sniffs their face....you can easily tell if fox pee is present by sniffing the grass, it is a very strong / pungent smell.