onedumbquestion
onedumbquestion

Reputation: 21

How can I namespace routes only in rails 7

I can add name spacing to explicit routes that begin with get, patch, put, post and not have to namespace models or controllers, I would just have to prepend the namespace to the paths in my views but how can I do the same for declared resources without having to edit my models and controllers?

Upvotes: 0

Views: 772

Answers (1)

Smek
Smek

Reputation: 1208

You would have to use a scope block to achieve this. From the docs (https://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing):

If instead you want to route /admin/articles to ArticlesController (without the Admin:: module prefix), you can specify the path with a scope block:

scope '/admin' do
  resources :articles, :comments
end

Upvotes: 1

Related Questions