LA Ruby Conference 2013 Refactoring Fat Models with Patterns by Bryan Helmkamp
Why Stack Overflow recommends it
Stack Overflow users link it when answering Rails questions about where business logic and form handling should live, especially for form objects and service objects.
Recommended by 2 people across 2 different months, 2013 to 2017.
What it is
A conference talk from LA Ruby Conference 2013 where Bryan Helmkamp of Code Climate explains how to break up bloated ActiveRecord models in Rails apps. It walks through patterns such as service objects and form objects that apply the Single Responsibility Principle. The recording is by Confreaks.
What people said
Recommends Houen · 2013-11 · Stack Overflow · on “Skinny controller passing hierarchical/nested data to view”
One of the widely accepted best practices for this kind of thing if Extracting a Form object . Bryan Helmkamp from Code Climate has written a very good blog post about this: [LINK] See section three "Extract Form Objects". The thing is, yes, you should definitely move business logic out of your controllers. But it does not belong in your data models (Activerecord models) either. You will want to use a combniation of number 2, "Extract Service Objects", and 3, "Extract Form Objects", in order to build a good structure for your app. You can also watch a good video of Bryan explaining these concepts here: [this video] For more on these topics, it is also highly recommended that you watch Confreaks c
Recommends dre-hh · 2014-06 · Stack Overflow · on “Advanced ruby on rails models and validation”
Because your registration process seems to be complex, I would go even futher as virtual attributes and use Form Objects 7 Patterns to Refactor Fat ActiveRecord Models [LINK] LA Ruby Conference 2013 Refactoring Fat Models [this video] ActiveModel Form Objects [LINK]
Cites Neil · 2017-03 · Stack Overflow · on “Rails form object with reform-rails with collections not working or validating”
I am using the reform-rails gem [LINK] In order to utilize a form object in my rails project. I realize a form object is probably overkill for the example code I use below, but it is for demonstration purposes. In the form I am creating a user , and associated to that user record are two user_emails . # models/user.rb class User < ApplicationRecord has_many :user_emails end # models/user_email.rb class UserEmail < ApplicationRecord belongs_to :user end Notice that I am not using accepts_nested_attributes_for :user_emails within the User model. It appears to me that one of the main points of form objects is that it helps you get away from using accepts_nested_attributes_for , so that is why I
Cites Neil · 2017-03 · Stack Overflow · on “Rails Form Object with Virtus: has_many association”
I am having a tough time figuring out how to make a form_object that creates multiple associated objects for a has_many association with the virtus gem [LINK] . Below is a contrived example where a form object might be overkill, but it does show the issue I am having: Lets say there is a user_form object that creates a user record, and then a couple associated user_email records. Here are the models: # models/user.rb class User < ApplicationRecord has_many :user_emails end # models/user_email.rb class UserEmail < ApplicationRecord belongs_to :user end I proceed to create a a form object to represent the user form: # app/forms/user_form.rb class UserForm include ActiveModel::Model include Vir