Day 3: Adding Features

Today, we dig a little deeper into Sinatra and use what we learn to add some features to our bookmarking application. We’ll make the application more robust with some validation, use block parameters and filters to refactor and improve our code, and end the day by implementing a new feature: adding tags to bookmarks.

Let’s begin by making the application more resistant to invalid input by providing validation.


We can create and update bookmarks, but we’re not validating anything. Let’s address that now. We want all bookmarks to have a title and a URL, and we want the URL’s format to be valid. DataMapper makes it easy to add these constraints to the Bookmark model:

class​ Bookmark ...

Get Seven Web Frameworks in Seven Weeks 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.