I understand that the Rails framework can be used to generate PHP code
That's not generally true. I suppose somebody somewhere may have made this happen, but their mental health problems would not be insignificant.
In general, Rails applications are written in a mixture of languages underpinned by Ruby, the others including HTML, CSS, Javascript. While HTML may be replaced by, for example, HAML, and Javascript (recently) by Coffeescript, with compilation steps occurring as needed, I've never seen Ruby being "compiled" down to PHP.
Ruby and PHP both appeared at about the same time, according to Wikipedia (here and here). Ruby was a fairly general-purpose scripting language that erupted into the Web World with the advent of Rails in 2004, whereas AFAIK, PHP was designed for web development.