Skip to content

Comment on Put Callback Logic Into Callback Objects [Rails]parent

Comments

Create a RequestFactory which is responsible for creating valid requests, put the hash generator in there. Then use the factory in the controller instead of directly creating the model.

That way you don't have the indirection of an ActiveRecord callback and you have your process of creating a request and assigning it a unique hash in a straightforward single process.

This makes sense. Thanks.

I've learned this the hard way. I have an app which has callback chains through 5+ models and it's basically impossible to figure out what's going on.

-C

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.