1

I have an application including a big backoffice part. I have a "backoffice" folder for my controllers, my helpers, and my views.

And typically, for many models I have a controller for the front, and another one in the backoffice folder. Like this:

-controllers/
      -products_controller.rb
      -backoffice/
           -products_controller.rb

The thing is, in many models, I have to do the same thing in front and in backoffice. Today, I have the same method in both controllers, which do the same thing. (I know...)

So, do you have any advice to dry this up?

Thanks !

mtreize
  • 57
  • 5

1 Answers1

0

Common patterns for making your controllers thinner and DRYer are concerns and service objects.

Concerns are modules with common functionality which can be included into a controller or a model. They are more encouraged by Rails, the folders for them are created by default in Rails 4.

Service objects are usually used in models, but it is worth to take a look at them. Which choice is better usually comes down to the concrete situation and personal preference.

Community
  • 1
  • 1
Jakub K
  • 1,645
  • 1
  • 12
  • 20