GoBlue1616
GoBlue1616

Reputation: 185

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?

Upvotes: 4

Views: 1406

Answers (1)

deefour
deefour

Reputation: 35370

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.

Upvotes: 8

Related Questions