you have two options: observers and taking advantage of a trick double piston extenders use. with observers, have a redstone line over them that they "look" into and power the pistons that are directly below them so that they "spit" the blocks out
if you can't make observers, have one piston(either one, doesn't matter which) have both a direct redstone line and a 2 repeater(that is, a repeater in its second position) face into a line powering the block the torch is on, which cannot be in direct contact with the piston. the other piston has a 2 repeater facing into it. done right, the side that has a torch should extend first and retract last. note that this implementation is also slower
note that this is not an exhaustive list, i could probably come up with more compact designs over time, but one relies on java being buggy, and the other relies on actual logic. if you were to make an improved design, base it off of the idea of the second one, not the first
the reason your design doesn't work is because of three simple issues: you're powering both pistons with the line that is meant to disable the redstone torch. two, you're not powering the block that holds the redstone torch, meaning it will not turn off. three, if those two issues would solve, the first piston would "jam" because you cannot have two pistons moving blocks in the same spots at the same time- one piston will wait for the other to move then only move after it realises it's powered by updating a block adjacent to it. it's more effective to just avoid this than trigger a block update in this scenario.
You could use an ABBA circuit, but for this purpose I believe it's overkill - the best approach is to get rid of one of the pistons, and handle the entire gate with just one piston:
The obvious problems are slime blocks sticking to neighboring dirt, so you'll have to surround them with non-sticky blocks - obsidian, furnaces, glazed terracotta or melons/pumpkins. Also, the 1-tall gap is enough for baby villagers to escape, so it might be a good idea to seal the area where the rail is stored when the door is closed.