Filters define code which should be executed before or after a request. They can be used for verifying conditions (such as user log in), logging, benchmarking, or setting up and tearing down information needed to handle a request.
- [Instructor] In this movie,…we're going to learn about route filters in Sinatra.…Route filters or just filters for short…is a way to define code that will be evaluated before…or after a route.…And the code in there can modify the request,…and the response objects if you need to.…But more importantly, you can set instance variables,…which are then available for your routes,…and your templates to use.…Let me give you an example.…Here's a before filter.…See that it starts out with just the word, before,…and then a code block after it.…
Everything from do to end.…And you can put absolutely any code that you want in there.…Anything that you want to be calculated…before every single route.…In this case, I'm saying that the first two things…that it should do are set instance variables…for username and language.…And it does that by looking at the session,…in the case of username,…and if it doesn't find a value there,…it defaults to guest.…Presumably, that's a value that I would make use of…on my templates.…My templates would have access to that instance variable.…
- 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
Ruby on Rails: Get More From ActiveRecordwith Kevin Skoglund4h 27m Intermediate
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.