Although it is not known who wrote the book, it was probably written during the reign of Israel's King David. The book centers around the theme of redemption and provides a beautiful picture of the coming Messiah (Jesus Christ). The events described in the book occur during the time of the judges. This was the time between when the Israelites left Egypt and when they asked God for a king like the nations around them (1 Samuel 8).
"In the days when the judges ruled, there was a famine in the land, and a man from Bethlehem in Judah, together with his wife and two sons, went to live for a while in the country of Moab. The man's name was Elimelech, his wife's name Naomi, and the names of his two sons were Mahlon and Kilion. They were Ephrathites from Bethlehem, Judah. And they went to Moab and lived there." NIV translation
This passage is a key to understanding the entire book of Ruth. These two verses tell us the time period for the events ("when the judges ruled") and also the fact that these people were Israelites (Jews). Moab was a land that was named after the son that Lot (Abraham's nephew) had with his oldest daughter (Gen. 19:30-38). Therefore, the Moabites were close to the lineage of Abraham but were not direct descendants and thus would be classified as Gentiles. We are told that, during this time, there was a famine in Israel but it must have not happened in Moab or at least it was less severe there. This Jewish man then takes his family to live among the Gentiles leaving the land of his people and his God behind. He could have stayed and trusted in God to sustain him and his family but instead he chose to go to a spiritually dead place and try to provide for his own needs.
"Now Elimelech, Naomi's husband, died, and she was left with her two sons. They married Moabite women, one named Orpah and the other Ruth. After they had lived there about ten years, both Mahlon and Kilion also died, and Naomi was left without her two sons and her husband." NIV translation
From this passage, we see that Elimelech, who had went to Moab to live because of famine, stayed and in fact died there. Then, the sons married Moabite (Gentile) women going against God's instructions in Deuteronomy 7. The sons also died in Moab and Naomi was left with her sons wives as her only relatives there. We can see from this passage how a little step away from God and living a holy life can lead to further disobedience. Because of Elimelech's decision to go to live among the Moabites for food, his sons grew up and married Moabite women. We probably can all look back on some of our decisions and see how a seemingly small and right step has in fact led us into disobedience of God. The key is to constantly be in prayer, seeking God's will, and listening for His gentle correction. If His gentle warnings are not heeded, we can find ourselves further away from God and deeper in disobedience just as happened to the men in this passage.