Reputation: 2130
Considering that I have a standard Rails directory structure in my project (the directory we get after a rails new
) and that I have several controllers (controllerA
, controllerB
, controllerC
, etc), where would be a good place to define a class that I want to use in all the controllers?
I was thinking about defining the class in application_controller.rb
and then use it, another option is define it in a file inside the models
folder and then require
that file.
Is there a Rails convention for this?
Upvotes: 0
Views: 34
Reputation: 13
You can also create your class in the controllers/concerns
directory.
Upvotes: 0
Reputation: 20253
Just create a services
directory under app
, put your class in there, and be done with it. No need to do a require as Rails will find it automatically.
Do not define a class in your controller. Do not put a plain old ruby objects in your models
folder.
Upvotes: 3