From the course: Ruby on Rails 5 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Custom helpers - Ruby on Rails Tutorial
From the course: Ruby on Rails 5 Essential Training
Custom helpers
- [Voiceover] Throughout this chapter, we've been looking at helper methods which Rails provides to make common tasks in our view templates easier. But we aren't limited only to the built in helpers. We can add our own custom helpers as well. That's what we're going to learn to do in this movie. Helper methods are going to be defined inside Ruby modules. You may have noticed that whenever we generate a controller, Rails generates a placeholder helper file that matches. There's nothing magic about that file it generates. You can write your own helpers too. The only important thing is that the file name and the helper's module name need to match. Any helper methods that are defined in that file will be available for use in our view templates. Custom Helpers are useful for a couple of different things. They are a good place to store code that we're going to need to call often. They're good for putting complex sections of code that we don't want cluttering up our view templates. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.