DRY in Views

Don’t Repeat yourself while creating Views in Rails.

I was confused when I starting working on Rails … but now I apply these rules.

Use Layouts to create page layouts to be shared by all views rendered by a controller.

Use components to create controller actions whose output needs to be used more than once

Use partials to create views, which need to be rendered more than once, in the same action or in different actions. [see collection option to render partial more than once in the same action]

Leave a Reply

Your email address will not be published. Required fields are marked *

7 + three =