From the course: Ruby on Rails 6 Essential Training: Models and Associations

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

How to skip callbacks

How to skip callbacks - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training: Models and Associations

Start my 1-month free trial

How to skip callbacks

- Once you add callbacks to your models, you typically want them to run all the time. Thus their purpose is to automatically perform some task, but every now and then it's useful to be able to skip them. So let's talk about how you would do that. The first way is that if you have an instance of an object and you want to update it, you can call update column or update columns, Update column is actually calling update columns behind the scenes. So they're really the same thing. Or if you want to get rid of an object without having any callbacks, you can call delete. Normally the method we use is destroy. Destroy does activate our callbacks, but delete does not. The reason these three methods skip our callbacks is because all three of them, construct SQL to submit directly to the database. That can be handy. Let's say for example, that we have a case where we have callbacks that are built into our…

Contents