To stop rust rings from metal containers in bath or kitchen like hair spray, cleansers, etc., coat the bottom with old nail polish.
I use the plastic lids from things like oatmeal containers, bread crumbs, etc on my bathtub ledge for my shaving cream cans or whatever else I need. It is hidden behind the shower curtain so it can't be seen. When the rust sticks to the plastic lid, I throw it in my recyclable can and use a new one.
LI Roe
There are some easy ways you can prevent rust rings on your tub from the can of shaving cream. This is a page about how to avoid rust rings from shaving cream cans.