render dựng view ngay trong request hiện tại — không tạo request mới, URL giữ nguyên, instance variables vẫn còn.redirect_to gửi HTTP 302, bảo browser tạo request mới đến URL khác — controller hiện tại kết thúc, action mới chạy từ đầu.
Lỗi kinh điển: dùng render sau POST tạo record → F5 submit lại form (double-submit). Quy tắc PRG (Post → Redirect → Get): sau POST thành công luôn dùng redirect_to.
ruby
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post, notice: "Tạo thành công!"
else
render :new, status: :unprocessable_entity # giữ lại lỗi validation
end
end