I am making a custom admin panel in a namespace "admin".
I have resources "courses" within that namespace.
But I would also like a route to "courses" that is not in that namespace:
eg: BOTH localhost:3000/admin/courses
AND localhost:3000/courses
It's OK if this requires different controllers.
My concern is that its not really DRY if i have both resources for the same route.
namespace admin do
resources :courses
end
and just
resources :courses
Is there a way to have one resource be shared between namespace and without namespace, or is the example above the way to go?
I'm not really sure I understand what you mean, but
namespace :something
is actually a shorthand forscope :something, module: :something, as: :something
scope :something
will add/something/
as a URL prefixscope module: :something
will add/something
as a controller prefix (controllers will be fetched undercontrolelrs/something/the_controller.rb
scope as: :something
will add thesomething
as a prefix for path helpersNow it's totally fine to have both in your routes
Does this answer your question ?
Oh wait ! There's also the possibility to use concerns !
EDIT : apparently this is what this guy also tried to do :D