I'd like to have a namespace in Rails where the module name in code is different than the path name that user sees in the URL.
One can make a namespace in routes like so:
namespace :admin_ui do
resources :posts
end
and this will match /admin_ui/posts to AdminUI::PostsController
.
How can I make this namespace match the path /admin, but use module AdminUI
?
Namespaces are used to organize a group of controllers. For example, you may wish to organize a group of controllers that are only accessible by the admin of your app, under the Admin:: namespace.
The difference lies in the paths generated. The paths are admin_posts_path and admin_comments_path for the namespace, while they are just posts_path and comments_path for the scope. You can get the same result as a namespace by passing the :name_prefix option to scope.
Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.
Found it:
namespace :admin_ui, path: 'admin' do
resources :posts
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With