Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ActiveModel Form Objects

ActiveModel Form Objects

Explain why it's better to use Plain Old Ruby Objects (POROs) to move business logic away from Ruby on Rails controllers. But it also shows how to use the best of ActiveRecord by using the ActiveModel to extend POROs.

Avatar for Olivier Robert

Olivier Robert

March 19, 2018
Tweet

More Decks by Olivier Robert

Other Decks in Programming

Transcript

  1. Intro • PORO managing complex controller flow: ◦ Lots of

    validation logic ◦ Creation of multiple models • Use ActiveRecord validations in the form object class: ◦ Handle data validation errors in the form ◦ Use ActiveModel naming conventions for generating form endpoints e.g. save(!), update(!), create(!)
  2. Thanks! Contact Nimbl3 [email protected] 399 Sukhumvit Road, Interchange 21 Klongtoey

    nua, Wattana Bangkok 10110 20th Floor, Central Tower 28 Queen's Road Central, Hong Kong nimbl3.com