DEV Community

Discussion on: Smarter Rails Services with Active Model Modules

Collapse
 
felipemalinoski profile image
Felipe Matos Malinoski

Awesome post! Can you please add the complete final class to the post??

The only thing I didn't understand was this:

attr_reader :user, :credit_card, :product_params, :products, :purchase
Enter fullscreen mode Exit fullscreen mode

where is the definition of :credit_cardand :purchase??

Thanks again for sharing this!

Collapse
 
sophiedebenedetto profile image
Sophie DeBenedetto

Glad you found it helpful!

I included the final version of the PurchaseHandler service class towards the end of the post. I removed the #credit_card attr_reader as it wasn't being used. The #purchase attribute is set in the #create_purchase method.

Also keep in mind that the code for actually creating a purchase is not described here and isn't totally relevant--just an example to illustrate how we can use some of these super helpful Active Model modules :)