Best and cheapest way to get to Slovakia from Austria

Hello! This August, my husband and I will be doing a 3 week backpacking trip in Europe. We plan on using the Eurail as our main transportation. However, Slovakia is not included in the ticket cost. Our tentative trip itinerary has us going from Vienna to Bratislava. Then Bratislava to Budapest. What is the most affordable and safest way to get to and from Bratislava? Thank you! Tiffany