Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
RailsConf 2017: Do Your Views Know Too Much? by Jason Charnes The logical place to put view-related logic is... inside your view, right? "A little logic here... a little logic there..." but all of a sudden we hardly recognize our views. A quick glance through our code and we can't tell our Ruby apart from our HTML. Don't worry; this is a fun opportunity for some refactoring! Come see several approaches you can start using today to clean up your views.
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 talk "Do Your Views Know Too Much?" at RailsConf 2017, Jason Charnes addresses the common issue of complex business logic being embedded within views in Ruby on Rails applications. By questioning the extent of logic in views, he suggests that many developers unknowingly let views become cluttered with operations best suited for controllers or models. Charnes emphasizes the importance of refactoring views to improve code maintainability and readability. Here are the key points discussed during the presentation: - **Introduction to the Problem:** Charnes kicks off by reflecting on his own experiences and anxiety about public speaking, which he overcame through involvement in the Rails community. He introduces the idea that views often become cluttered with code that should reside elsewhere. - **Code Smells in Views:** He categorizes certain coding patterns in views as code smells, indicating areas where better practices could be applied. For example, direct database calls within views, reliance on ActiveRecord, and multiple conditionals that complicate the view's purpose. - **Refactoring Approaches:** Charnes presents three primary ways to refactor views to clean them up: - **Unit Level Refactoring:** Simplifying view logic by shifting responsibility to models with methods that encapsulate complex logic, thus making the view more declarative. - **Helper Methods:** Utilizing helpers to centralize logic that may be needed in multiple places within views, promoting the DRY (Don't Repeat Yourself) principle. - **Decorators:** Introducing decorators to wrap model objects and provide additional presentation logic without polluting the original model, allowing for cleaner view templates. - **Conditionals in Views:** He highlights the need to minimize conditionals in views, advocating for placing such logic into helpers to keep views focused primarily on data presentation. - **Key Takeaways:** Charnes wraps up by reiterating four essential principles for better view design: - Views should not access the database directly. - Views should minimize repetition of code. - Views should avoid computing data. - Views should reduce conditional logic as much as possible. Charnes encourages developers to prioritize the readability and maintainability of their views, suggesting that well-structured views contribute to overall code quality and easier collaboration within teams. Overall, the talk provides a compelling case for view refactoring, coupled with practical strategies that developers can implement immediately to enhance their Rails applications.
Suggest modifications
Cancel