Where should my unmodeled / uncontrolled code be located?

I wrote a rails application that follows the usual directory structure (model code in models, controller code in controllers).

But now I'm working on a new function, and for this I wrote a few (what I would call) "service" code.
A new feature is to import some data into the system, at the moment these are two classes for import, but can expand to more.

I do not believe that the new code belongs to the model, because it does not model any object (it is not directly connected to any object. I, of course, do not think that this belongs to the controller, since this is not presentation logic.

So, I created the "application / service" directory and placed it there. I also created the "test / services" directory, where I put my tests.

Everything is good and good, what I thought, but when I run "rake: test" or "autotest", my tests of new services are not executed.
Now I expect that there is a way to make the rake pick them up, but is it a warning flag that I did something wrong?
Is there another place the code should live in, or am I somehow not doing the "Rails path"?

As a rule, whenever I came across such a problem, before I discovered that the rails already have a solution, but I did not know about this agreement. Is this one of these cases?

+14
ruby ruby-on-rails rake
Nov 12 '08 at 20:02
source share
2 answers

This is what the lib folder is.

The lib folder is in an auto-looking path, so you may have

class MyFoo end 

in lib/my_foo.rb and then just calling

 MyFoo.new 

code will be downloaded from the controller without requiring require 'my_foo'

+22
Nov 12 '08 at 20:04
source share

./lib is definitely a place to go.

Another place to put in the initialization directory in config depends on what you are doing. You might also think that all of this should be in the plugin, but if this is a little functionality, probably it is not worth it.

+1
Nov 12 '08 at 20:07
source share



All Articles