Rick, Daryl, Michonne, and Carl planned for this exact event to happen. They knew that the Termites would put them in the fridge given any provocation. Terminus is clearly too large and too well protected for four people, even four insane killing machines like Rick and Company, to roll in and rescue the rest of the Atlanta Survivors.
Rick was led to the traincar as part of his plan.
Rick even thought about losing his Colt, which would be a terrible loss to the Survivors, so he stowed it away to be retrieved later. That Colt is probably the single most accurate gun in a hundred miles.
When the Survivors showed thier weapons to the Termites, they didn't show all of them. They each have hide-away weapons. It's an old magician's trick - slight of hand. They showed the obvious weapons, and when they were eventually trapped they turned over those obvious weapons. They were patted down in the most superficial way. Cowboy boots can hold a pretty decent sized knife, Michonne could easily hide, well, umm, probably not much they way she's dressed. Okay. So three of them have weapons. ;)
At the end of Season 4, when Rick is in the traincar, he very clearly has a plan.