You can't, directly. There's no Lua access function for that; it looks like it's all handled internally.
BUT, there's an indirect way to do it. The City View UI creates the Production tooltip in the upper-left corner of the city screen using the command
local strProductionHelp = GetProductionTooltip(pCity);
which has a line giving the "+25% production for railroad connection" or something similar. So all you'd need to do is parse that Production tooltip string to see if the word "railroad" appears in it in the appropriate spot. If so, then the city has a rail connection.
The only problem I can think of would be localization; you'd have problems with other languages. So you'd want to find whatever text key says "railroad" in the database, and search for THAT string.