Back to Browse

How to use the Delegate Pattern in Ruby on Rails

6.0K views
Nov 30, 2020
11:45

When working with more complex associations in a Ruby on Rails app you may find yourself in an object chaining problem upon rendering data to a view or helper. The delegate pattern is a handy built-in feature to Ruby on Rails to help with this issue. What is delegate exactly? Taking a deeper look at the Ruby on Rails API documentation you can see delegate defined as a Ruby class method used to easily expose contained objects' public methods as your own. That sounds more complicated than it is and luckily it's pretty simple to configure. In the example, you'll find in this tutorial I used a User model and a Profile model to demonstrate this pattern. You'll need something similar to follow along but pretty much anything with a relationship intact should suffice. 📌 Continue reading: https://web-crunch.com/posts/how-to-use-the-delegate-pattern-ruby-on-rails ========== Hi, My name is Andy Leverenz and I work as a product designer and developer. For fun, I design, code, and write. Check out my blog called Web-Crunch https://web-crunch.com where I publish design and development tutorials with the occasional vlog. ♥️ Sponsor me on GitHub https://github.com/sponsors/justalever ☕️ Keep me awake. Buy me a coffee https://www.buymeacoffee.com/webcrunch 📰 One-Click Subscribe: https://www.youtube.com/user/webcrunchblog?sub_confirmation=1 💻 Previously published at: https://web-crunch.com/posts/how-to-use-the-delegate-pattern-ruby-on-rails 👋 Latest Course: HELLO HTML & CSS (coming soon)👋 https://hellohtmlcss.com 💎Ruby on Rails Course: HELLO RAILS https://hellorails.io 💻 Check out the blog: https://web-crunch.com 🦄 Check out my personal site: https://justalever.com 🚀 Links: Weekly Newsletter: https://digest.web-crunch.com/ Twitter: https://twitter.com/webcrunchblog Github: https://github.com/justalever 📘Check out my book on UX Design: "LUXD: Learn User Experience Design" https://web-crunch.com/products/luxd 📙 Check out my FREE book on Tumblr Theming: "Pro Tumblr Theming" https://web-crunch.com/products/ptt

Download

0 formats

No download links available.

How to use the Delegate Pattern in Ruby on Rails | NatokHD