Ruby On Rails Package By Feature

Viewed 343

Is there any way to package your code by feature in rails? I would like to structure my project so that each feature has its controllers, jobs, mailers, layouts and helpers in its own folder. e.g.

app
----user
--------jobs
--------controllers
--------mailers
--------layouts
--------helpers

----company
--------jobs
--------controllers
--------mailers
--------layouts
--------helpers

where user and company are seperate features.

2 Answers

I've done this in my app and its pretty easy.

You create your file structure the way you want it and then you just put config.autoload_paths += %W(#{config.root}/app/user/jobs) or whatever other subdirectory you want into your application.rb folder.

People might say this is not the rails way but I feel your pain when your project gets really big and hard to navigate.

Checkout Trailblazer gem. It is an extension on the basic MVC pattern.

Related