Comments about a design pattern code at the Rails Conf


I just watch the talk of @Justin_Gordon at the Rails Conf.

I have a lot of interogation about the last subject. Justin say we must use POR (Pure Old Rails) but I disagree. I think Services Objects are good to do single action. First, It follow the SRP. Models sucks the responsabilities. It become harder to test with the time. Secondly, a service object should be callable by different objects, even by the console.

I also like to use form objects. It’s simpler than nested attributes. It’s very useful when a form have a complex logic or multiple models.

So, I like Form Objects and Service Objects but I am not advanced of how and when to use it. It’s a bit foggy for me.

@Justin_Gordon, do you think those patterns are not useful?

Thanks for your talk. It make me think.

Hi @Guirec_Corbel, thanks for post. I started my talk in the same boat as you, but after getting personal feedback from DHH, I changed my post.

The net of it is this:

  1. Keep your code as simple as possible, based on the framework that you’re using. No extra classes breaking out what controllers do, for example.
  2. Changing your code to make it more complicated just to make the tests simpler is incorrect. I started off doing that and got feedback in my pull requests.

Basically, use models for anything domain based, testing with model specs. Put the coordination aspects in controllers, and test the controller behavior primarily in integration (capybara) tests.