We have a bunk in our 5er and we bought a wooden fold-down bed rail. It has 2 "arms" than go under the mattress and those hold the rail (looks like a wooden gate) in place. The rail can be tipped down by lifting it up and pulling out slightly. My daughter did not like the lumps under the mattress (apparently she is princess material!) so I cut the "arms" to about 3 inches long and screwed them into the plywood under the mattress and they have worked great ever since.
07 Cruiser 29BT
04 2500 Hemi Ram Quad Cab