Sinatra allows defining Ruby methods as custom helpers. These helpers are useful for organizing common tasks. They can be used in the Ruby code block or be called in the ERB code embedded in template files.
- [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 the content type or cache control.…
- Installing Sinatra
- Launching the server
- Defining routes
- Using route patterns and parameters
- Redirecting requests
- Rendering dynamic templates
- Using partial templates and layouts
- Defining custom helpers
Skill Level Intermediate
Ruby on Rails 5 Essential Trainingwith Kevin Skoglund10h 21m Beginner
3. Helpers and Filters
4. Useful Techniques
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.