Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
Unwieldy templates (a.k.a. views) are all too common in Rails apps, even among teams that otherwise craft high-quality code. Being brought into or having to maintain a project with poorly-crafted templates leads to extreme frustration and less than-adequite-velocity. At philosophie, we have started to use a few simple patterns that result in templates that are easier to maintain. By investing a small amount of time up-front learning and applying these patterns we have saved countless hours in the long run. Topics include: * The Decorator Pattern * Using View objects * Sanely building forms * And more! Help us caption & translate this video! http://amara.org/v/FGas/
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
In the video "Maintainable Templates," Brendan Loudermilk discusses challenges with maintaining templates in Rails applications and shares effective patterns to create more manageable views. He emphasizes that while the Rails community often focuses on models and controllers, templates are frequently neglected, leading to frustration and reduced development velocity. The presentation outlines several common issues and solutions to improve template maintainability. ### Key Points: - **Problem of Markup Repetition**: Unmaintainable templates often result from repeated markup in various views, such as sidebars and headers. To combat this, Loudermilk encourages developers to abstract these components into partials, making the codebase cleaner and reducing repetition. - **Logic in Templates**: He highlights the detriment of placing logic directly into views, as this leads to messy and hard-to-test code. Instead, Loudermilk demonstrates how to use view helpers and decorators to isolate logic from templates. By putting logic in helpers, developers can centralize frequently used code, promoting better organization. - **Decorator Pattern**: Loudermilk introduces the Decorator Pattern as an advanced solution. This pattern encapsulates presentation logic into separate classes that wrap model instances, making it easier to manage and test. He explains how to implement decorators and suggests using the Draper gem to simplify the creation of decorator classes that provide a clean interface for views. - **Presentation Models**: He discusses presentation models for UI elements that do not directly relate to a model instance. These models allow developers to encapsulate all necessary logic for rendering specific parts of a UI without cluttering views or decorators. - **Form Builders**: Loudermilk provides an example of custom form builders in Rails, demonstrating how they can significantly streamline form rendering and enhance maintainability across an application. - **Use of I18n**: He advises using internationalization (I18n) to centralize text management in applications, reducing clutter in templates and simplifying content updates. ### Conclusion: Loudermilk concludes by encouraging developers to be proactive in maintaining clean and manageable templates. He emphasizes that investing time in applying these patterns can lead to significant long-term savings in development time and improve collaboration within teams. Implementing solutions like the Decorator Pattern, presentation models, and custom form builders are vital steps in transforming unwieldy templates into maintainable components in Rails applications.
Suggest modifications
Cancel