A chance to attend Ranger school will be completely driven by your branch managers (the HRC types) and your unit. Slots come down on an obviously limited basis, and the chance to attend requires not only that your unit have a slot (be it your schoolhouse unit such as IOBC or your actual unit of assignment thereafter), but that you meet all the requirements for attendance and that your personal timeline permits it.
It is, generally, rare for officers to attend once they've been sent to their unit of assignment. At that point, you are expected to put your duties first (being a platoon leader, a staff officer, etc.). Most commanders are reluctant to let an officer walk out the door for 3 months (Pre-Ranger, Ranger, plus a likely recycle) to go get another badge.
There are cases where it happens, but the vast, vast majority receive their Ranger slot immediately following their OBC assignment, prior to signing in to their first unit. That also requires, of course, that your orders permit it. You may have a slot, but if your unit is set to go somewhere your orders may not allow you time to do a school enroute to your first duty assignment.
It is possible for branch detailed officers to attend, but they are not given priority. Also, remember that there is often a hold for Ranger school, and you might burn 6 or 7 months of your short 3 years as an Infantry officer simply waiting for and attending the Ranger course. When you count in your OBC time, you could lose a year or more of your 3 years in the infantry simply sitting at Benning. These days, many elect to go join the fight and maximize their unit time before reverting to their non-combat branch.