From the course: Ruby on Rails 6 Essential Training

Unlock the full course today

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

Using partials and helpers to organize code

Using partials and helpers to organize code - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training

Start my 1-month free trial

Using partials and helpers to organize code

- In this movie, I want to introduce you to partials and helpers. Partials and helpers are important for having good code organization in your Ruby on Rails project. And most importantly they help you to not repeat yourself. And remember that's one of the fundamental mantras. Dry don't repeat yourself. Partials are going to be partial templates and we want to create partial templates that we can share between a number of other templates. Helpers are methods that can be called in the view templates. So we can move Ruby code into those helpers and call on it when needed. In the last movie you may have noticed that our new form and our edit form have a lot of code in common especially this table of form fields. What I want to do now is use a partial so that they can share that same information and we won't have to repeat it anymore. The convention for doing that is to create a new file inside the subjects and we're…

Contents