O'Reilly logo

Seven Web Frameworks in Seven Weeks by Frederic Daoud, Jack Moffitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

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:

sinatra/validation/bookmark.rb
 
class​ Bookmark ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required