User.find(user_id) will raise an exception if no user found. Maybe it's better to use User.find_by(id: user_id), so if no user found it will set user variable to nil and user presence validation will handle this error?
Also what about to set visibility level of create_purchase, create_invoice and notify_user methods to private since we don't need to access these methods outside of the class?
Great post btw!
Engineer at GitHub, graduate of + former teacher at Flatiron School. Cat lover, but I admit I have a dog. Supporting students and junior devs through https://www.break-in.tech/
User.find(user_id)
will raise an exception if no user found. Maybe it's better to useUser.find_by(id: user_id)
, so if no user found it will set user variable to nil and user presence validation will handle this error?Also what about to set visibility level of create_purchase, create_invoice and notify_user methods to private since we don't need to access these methods outside of the class?
Great post btw!
Hi,
Yes you are totally right about the switch to
find_by
. I also agree with making those methods private. Thanks for the feedback!