Episodes
Jeffrey Soong said about 2 years ago on ActiveRecord Callbacks :
is there any benefit to writing the generate_token with begin/end over something like that?

def generate_token
   while self.class.exists?(token: token)
     self.token = SecureRandom.hex(8)
   end
end

almokhtar said about 2 years ago on ActiveRecord Callbacks :
what the service thing you did , what i must search for to learn more about this .
Thank you 

richstone.io said over 1 year ago on ActiveRecord Callbacks :
Nice episode! You argue to not having many callbacks in a model, which I think is good. What if there is already a fat model with tons of callbacks? Is there a certain useful approach to refactor them? I mean, apart from extracting functionality into its own services, as described in the video. (although, I found it to be very nice examples)

David Kimura PRO said over 1 year ago on ActiveRecord Callbacks :
  richstone.io  If you find yourself in a situation where there are already a bunch of callbacks in the model and you're wanting to clean things up a bit, there are a few approaches you can take. First, start to separate and isolate things. You can do this with namespaced concerns. This will help you get an overview at a glance what you'll be dealing with. Otherwise, code from the model will start to blend in and it will be confusing. Once things are separated, the decisions can be made to leave it the way it is or to start removing the callbacks. Having appropriate test can help expose any breaks in your refactors so I'd say that will be an important part; especially for a large model. Try to identify where the parts are that could ultimately trigger the callback as you'll likely need to touch those areas of code. Overall, I think that the main ones that I would focus on would be the ones that involve other models. Those tend to be the most brittle and the most trouble makers. A callback which only affects the model record itself is usually okay and could be argued that it is "good enough" to be left alone.

Login to Comment