From the course: Learning Sinatra

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Define custom helpers

Define custom helpers

From the course: Learning Sinatra

Start my 1-month free trial

Define custom helpers

- [Instructor] In this chapter, we will learn how to use helpers and filters in Sinatra. Sinatra does not have a lot of built in helpers. It's lean by design. And you're meant to add in helpers as you need, you can define your own, or you can pull them in from other libraries, other Ruby Gems or other sources. We have encountered a few of the built in helpers already. Redirect is a built in helper and so is send_file. If you think about redirect, we just simply type redirect and tell it the URL we want to redirect to. Behind the scenes, it does a lot of extra work for us. It sets the status code, it returns a head tag, it tells the browser what the new URL ought to be. We don't have to do any of that, that's all wrapped up in a very simple function for our convenience and that's the idea behind helpers. Taking something that we could do the hard way and helping us to do it much easier. There are a handful of other build in helpers that allow you to do more advanced things, like set…

Contents