How to make object that pushes from behind.

I want to make an object(B) pushing object(A) from behind. The object (A) is hung on a rail. When the object (B) pushes from behind, the object (A) moves along the rail.
(like Hill Lifter of roller coaster)

just apply rigidbody to both of the objects