From the course: Ruby on Rails 6: Controllers and Views

Unlock the full course today

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

Custom helpers

Custom helpers - Ruby on Rails Tutorial

From the course: Ruby on Rails 6: Controllers and Views

Start my 1-month free trial

Custom helpers

- [Instructor] Now that we've learned about some of the useful Rails helpers, it's time to learn how to write your own custom helpers. This is an extremely powerful technique that you're going to be using a lot. Helpers are simply Ruby modules with methods to find inside of them. Whenever we generate a controller, Rails will generate a helper file to match automatically. You can also create your own. The separate file that it creates is just to help keep you organized. All of the helpers in all helper files are available in all of the view templates. It's not like the controllers, where code that's in one controller, isn't accessible in another one. Helpers are useful for a few different things. The first, is that they can be a good place to store code that you're going to need to call often. Remember, don't repeat yourself, D-R-Y. They're also good for complex sections of code that you don't want cluttering up your…

Contents