Artwork

Andrew Mason and Julie J에서 제공하는 콘텐츠입니다. 에피소드, 그래픽, 팟캐스트 설명을 포함한 모든 팟캐스트 콘텐츠는 Andrew Mason and Julie J 또는 해당 팟캐스트 플랫폼 파트너가 직접 업로드하고 제공합니다. 누군가가 귀하의 허락 없이 귀하의 저작물을 사용하고 있다고 생각되는 경우 여기에 설명된 절차를 따르실 수 있습니다 https://ko.player.fm/legal.
Player FM -팟 캐스트 앱
Player FM 앱으로 오프라인으로 전환하세요!

Mastering Rails Callbacks – Deciphering the Secrets of Active Record

30:42
 
공유
 

Manage episode 399917803 series 3375882
Andrew Mason and Julie J에서 제공하는 콘텐츠입니다. 에피소드, 그래픽, 팟캐스트 설명을 포함한 모든 팟캐스트 콘텐츠는 Andrew Mason and Julie J 또는 해당 팟캐스트 플랫폼 파트너가 직접 업로드하고 제공합니다. 누군가가 귀하의 허락 없이 귀하의 저작물을 사용하고 있다고 생각되는 경우 여기에 설명된 절차를 따르실 수 있습니다 https://ko.player.fm/legal.

In this episode of Ruby for All, Andrew and Julie discuss the intricacies of callbacks in Active Record models. They talk about their experiences, the pros and cons of using callbacks, and the issues they faced. They also share some helpful use cases for callbacks, including user authentication, logging and auditing, custom slug generation, and the concept of “hooks.” Also, Andrew and Julie review their ways of dealing with callbacks testing and debugging in a Rails application. Press download now to hear more!

[00:02:32] Let’s learn about “callbacks” in Rails as Andrew explains what they are and uses an example of a blog post to explain how a callback might function when saving a post.

[00:03:56] Julie inquires if Tiptap can be used in a browser for apps and they discuss before-save callbacks in a post model and how they can be used to extract and save a title.

[00:06:19] Andrew elaborates on the three different types of callbacks: before, after, and around callbacks, and gives examples of each.

[00:10:06] They discuss practical uses for before-validation callbacks, such as setting default values.

[00:11:12] Andrew clarifies the concept of “hooks” in programming, comparing it to callbacks.

[00:12:18] Julie asks for examples of actions taken after validation versus before validation.

[00:13:19] Andrew talks about how a file upload, an after-create callback can be used for processing the file such as generating thumbnails or updating related resources. He lists examples use cases for callbacks like hashing passwords before saving to the database during user authentication, triggering email notifications after a comment is posted, and logging and auditing activities like user sign-ups or errors.

[00:15:57] Julie is curious about whether deleted accounts really remove all user data or just make it as inaccessible, noting some services offer a soft delete option with a time window to recover the account. Andrew has not yet encountered the fallback log issue he set up but explains how before-destroy callbacks could be used to implement a time-based soft delete system.

[00:17:19] Andrew describes using before-create callbacks for generating custom slugs for blog posts automatically.

[00:17:54] Andrew recalls a discussion at RailsConf about the diverse opinions on using callbacks, with some developers strongly against them and others in favor. He acknowledges that while callbacks can simplify complex operations, they can also make debugging difficult and can become problematic if used excessively or inappropriately.

[00:23:00] Julie asks Andrew where he stands on the use of callbacks, and he positions himself in the middle, closer to using them when appropriate.

[00:25:16] Andrew emphasizes being cautious with callbacks and explains that callbacks are useful when certain actions need to happen automatically without explicit instruction every time a record is saved.

[00:27:40] Andrew discusses the challenges of testing callbacks, as they can require additional setup in tests and slow down the test suite. He concludes that callbacks are an integral part of Rails, he advises against using them as the first solution and recommends weighing their pros and cons carefully.

Panelists:

Andrew Mason

Julie J.

Sponsors:

Honeybadger

GoRails

Links:

Andrew Mason X/Twitter

Andrew Mason Website

Julie J. X/Twitter

Julie J. Website
Active Record Callbacks

Tiptap

  • (00:00) - Intro and Topic Overview
  • (02:32) - Introduction to Callbacks in Rails
  • (03:56) - Discussing Before-Save Callbacks and Tiptap
  • (06:19) - Types of Callbacks: Before, After, and Around
  • (10:06) - Uses for Before-Validation Callbacks
  • (11:12) - Hooks vs Callbacks
  • (12:18) - Practical Use Cases for Callbacks
  • (15:57) - Soft Delete Options and Before-Destroy Callbacks
  • (17:19) - Generating Custom Slugs with Before-Create Callbacks
  • (17:54) - Diverse Opinions on Using Callbacks from RailsConf
  • (23:00) - Andrew's Not an Expert
  • (25:16) - Caution and Appropriate Use of Callbacks
  • (27:40) - Challenges of Testing Callbacks
  continue reading

69 에피소드

Artwork
icon공유
 
Manage episode 399917803 series 3375882
Andrew Mason and Julie J에서 제공하는 콘텐츠입니다. 에피소드, 그래픽, 팟캐스트 설명을 포함한 모든 팟캐스트 콘텐츠는 Andrew Mason and Julie J 또는 해당 팟캐스트 플랫폼 파트너가 직접 업로드하고 제공합니다. 누군가가 귀하의 허락 없이 귀하의 저작물을 사용하고 있다고 생각되는 경우 여기에 설명된 절차를 따르실 수 있습니다 https://ko.player.fm/legal.

In this episode of Ruby for All, Andrew and Julie discuss the intricacies of callbacks in Active Record models. They talk about their experiences, the pros and cons of using callbacks, and the issues they faced. They also share some helpful use cases for callbacks, including user authentication, logging and auditing, custom slug generation, and the concept of “hooks.” Also, Andrew and Julie review their ways of dealing with callbacks testing and debugging in a Rails application. Press download now to hear more!

[00:02:32] Let’s learn about “callbacks” in Rails as Andrew explains what they are and uses an example of a blog post to explain how a callback might function when saving a post.

[00:03:56] Julie inquires if Tiptap can be used in a browser for apps and they discuss before-save callbacks in a post model and how they can be used to extract and save a title.

[00:06:19] Andrew elaborates on the three different types of callbacks: before, after, and around callbacks, and gives examples of each.

[00:10:06] They discuss practical uses for before-validation callbacks, such as setting default values.

[00:11:12] Andrew clarifies the concept of “hooks” in programming, comparing it to callbacks.

[00:12:18] Julie asks for examples of actions taken after validation versus before validation.

[00:13:19] Andrew talks about how a file upload, an after-create callback can be used for processing the file such as generating thumbnails or updating related resources. He lists examples use cases for callbacks like hashing passwords before saving to the database during user authentication, triggering email notifications after a comment is posted, and logging and auditing activities like user sign-ups or errors.

[00:15:57] Julie is curious about whether deleted accounts really remove all user data or just make it as inaccessible, noting some services offer a soft delete option with a time window to recover the account. Andrew has not yet encountered the fallback log issue he set up but explains how before-destroy callbacks could be used to implement a time-based soft delete system.

[00:17:19] Andrew describes using before-create callbacks for generating custom slugs for blog posts automatically.

[00:17:54] Andrew recalls a discussion at RailsConf about the diverse opinions on using callbacks, with some developers strongly against them and others in favor. He acknowledges that while callbacks can simplify complex operations, they can also make debugging difficult and can become problematic if used excessively or inappropriately.

[00:23:00] Julie asks Andrew where he stands on the use of callbacks, and he positions himself in the middle, closer to using them when appropriate.

[00:25:16] Andrew emphasizes being cautious with callbacks and explains that callbacks are useful when certain actions need to happen automatically without explicit instruction every time a record is saved.

[00:27:40] Andrew discusses the challenges of testing callbacks, as they can require additional setup in tests and slow down the test suite. He concludes that callbacks are an integral part of Rails, he advises against using them as the first solution and recommends weighing their pros and cons carefully.

Panelists:

Andrew Mason

Julie J.

Sponsors:

Honeybadger

GoRails

Links:

Andrew Mason X/Twitter

Andrew Mason Website

Julie J. X/Twitter

Julie J. Website
Active Record Callbacks

Tiptap

  • (00:00) - Intro and Topic Overview
  • (02:32) - Introduction to Callbacks in Rails
  • (03:56) - Discussing Before-Save Callbacks and Tiptap
  • (06:19) - Types of Callbacks: Before, After, and Around
  • (10:06) - Uses for Before-Validation Callbacks
  • (11:12) - Hooks vs Callbacks
  • (12:18) - Practical Use Cases for Callbacks
  • (15:57) - Soft Delete Options and Before-Destroy Callbacks
  • (17:19) - Generating Custom Slugs with Before-Create Callbacks
  • (17:54) - Diverse Opinions on Using Callbacks from RailsConf
  • (23:00) - Andrew's Not an Expert
  • (25:16) - Caution and Appropriate Use of Callbacks
  • (27:40) - Challenges of Testing Callbacks
  continue reading

69 에피소드

모든 에피소드

×
 
Loading …

플레이어 FM에 오신것을 환영합니다!

플레이어 FM은 웹에서 고품질 팟캐스트를 검색하여 지금 바로 즐길 수 있도록 합니다. 최고의 팟캐스트 앱이며 Android, iPhone 및 웹에서도 작동합니다. 장치 간 구독 동기화를 위해 가입하세요.

 

빠른 참조 가이드

탐색하는 동안 이 프로그램을 들어보세요.
재생