DEV Community

Discussion on: Smarter Rails Services with Active Model Modules

Collapse
 
skoddowl profile image
skoddowl • Edited

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!

Collapse
 
sophiedebenedetto profile image
Sophie DeBenedetto

Hi,

Yes you are totally right about the switch to find_by. I also agree with making those methods private. Thanks for the feedback!