Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize controller directory in rails 4 without messing up routes

First off... I love keeping things organized. As such, it's starting to bother me that the list of controllers in my app just keeps growing in one large directory.

Ideally, I could construct a list of subdirectories and organize my controllers. You can do this with namespaces, but then the subdirectory shows up within the url, and I really don't want this to happen.

Does anyone have a different strategy to keep their controllers, helpers, models, and views organized?

like image 578
GoBlue1616 Avatar asked Feb 14 '23 16:02

GoBlue1616


1 Answers

Ideally, I could construct a list of subdirectories and organize my controllers. You can do this with namespaces, but then the subdirectory shows up within the url, and I really don't want this to happen.

You can scope the routes against a specific namespace. Read Controller Namespaces and Routing

scope module: 'admin' do
  resources :posts, :comments
end

Will generate routes at /posts while the controller is at Admin::PostsController found in app/controllers/admin/posts_controller.rb.

like image 74
deefour Avatar answered Apr 28 '23 01:04

deefour