Chapter 15. Saving and Loading Data: Keep It Around
Your web app is just throwing usersâ data away. Youâve set up a form for users to enter data into. Theyâre expecting that youâll save it, so that it can be retrieved and displayed to others later. But thatâs not happening right now! Anything they submit just disappears.
In this, our final chapter, weâll prepare your app to save user submissions. Weâll show you how to set it up to accept form data. Weâll show you how to convert that data to Ruby objects, how to save those objects to a file, and how to retrieve the right object again when a user wants to see it. Are you ready? Letâs finish this app!
Saving and retrieving form data
In the last chapter, we learned how to use the Sinatra library to respond to HTTP GET requests from a browser. We built a Movie
class and embedded movie data into an HTML page.
We even learned how to serve an HTML form so that users can enter new movie data.
But thatâs as far as HTTP GET requests can take us. We have no way to submit that form back to the server. And we wouldnât know how to save the form data if we got it.
In this chapter, weâre going to fix all that! Weâll learn how to take the userâs form data and convert it to Ruby objects for easy storage. Weâll also learn how to save those objects to a file and then retrieve them for display later. This chapter is going to bring ...
Get Head First Ruby now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.