Artwork

Content provided by Charles Max Wood. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by Charles Max Wood or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.
Player FM - Podcast App
Go offline with the Player FM app!

ActiveRecord Observers

7:12
 
Share
 

Archived series ("Inactive feed" status)

When? This feed was archived on July 14, 2021 01:41 (3y ago). Last successful fetch was on June 05, 2018 17:42 (6+ y ago)

Why? Inactive feed status. Our servers were unable to retrieve a valid podcast feed for a sustained period.

What now? You might be able to find a more up-to-date version using the search function. This series will no longer be checked for updates. If you believe this to be in error, please check if the publisher's feed link below is valid and contact support to request the feed be restored or if you have any other concerns about this.

Manage episode 150840408 series 1008985
Content provided by Charles Max Wood. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by Charles Max Wood or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.
About a month ago, I talked about ActiveRecord Callbacks. Observers are a way of moving callbacks out of the Model. Usually this is done to adhere to the Single Responsibility principle. So, for example, programmers will move sending an email when a record is updated or created to an Observer. class UserObserver < ActiveRecord::Observer def after_create(user) UserMailer.sign_up(user).deliver end end Observers should be included in your app/models folder and named using the same convention as your models. So in this case, this observer would be saved to /app/models/user_observer.rb. To load the observer in your application, you need to include this line in your config/application.rb config.active_record.observers = :user_observer Finally, you can observe more than one model with the same observer. class SignUpObserver < ActiveRecord::Observer observer :user, :admin def after_create(user) UserMailer.sign_up(user).deliver end end I personally like Observers when they help keep you from repeating code or increase code readability. In many cases, I simply keep callbacks in models and violate the Single Responsibility Principle.
  continue reading

33 episodes

Artwork
iconShare
 

Archived series ("Inactive feed" status)

When? This feed was archived on July 14, 2021 01:41 (3y ago). Last successful fetch was on June 05, 2018 17:42 (6+ y ago)

Why? Inactive feed status. Our servers were unable to retrieve a valid podcast feed for a sustained period.

What now? You might be able to find a more up-to-date version using the search function. This series will no longer be checked for updates. If you believe this to be in error, please check if the publisher's feed link below is valid and contact support to request the feed be restored or if you have any other concerns about this.

Manage episode 150840408 series 1008985
Content provided by Charles Max Wood. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by Charles Max Wood or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.
About a month ago, I talked about ActiveRecord Callbacks. Observers are a way of moving callbacks out of the Model. Usually this is done to adhere to the Single Responsibility principle. So, for example, programmers will move sending an email when a record is updated or created to an Observer. class UserObserver < ActiveRecord::Observer def after_create(user) UserMailer.sign_up(user).deliver end end Observers should be included in your app/models folder and named using the same convention as your models. So in this case, this observer would be saved to /app/models/user_observer.rb. To load the observer in your application, you need to include this line in your config/application.rb config.active_record.observers = :user_observer Finally, you can observe more than one model with the same observer. class SignUpObserver < ActiveRecord::Observer observer :user, :admin def after_create(user) UserMailer.sign_up(user).deliver end end I personally like Observers when they help keep you from repeating code or increase code readability. In many cases, I simply keep callbacks in models and violate the Single Responsibility Principle.
  continue reading

33 episodes

All episodes

×
 
Loading …

Welcome to Player FM!

Player FM is scanning the web for high-quality podcasts for you to enjoy right now. It's the best podcast app and works on Android, iPhone, and the web. Signup to sync subscriptions across devices.

 

Quick Reference Guide