Spasitel
Spasitel

Reputation: 169

Model names and namespaces

I have a model called Admin and I would like to create a namespace with the same name. When I do it Admin is not a module is raised. Is there a way how the specify the route or another way to solve this?

Admin is a Devise model.

the namespace in routes.rb:

namespace :admin do
    resources :buildings
end

And the controller controllers/admin/buildings_controller.rb

module Admin
  class BuildingsController < Admin::AdminController
    before_action :authenticate_admin!

Upvotes: 0

Views: 835

Answers (1)

codenamev
codenamev

Reputation: 2208

The problem you're facing is not route-specific, but rather Ruby-specific. A Rails model is a Ruby class. You cannot have a class and a module with the same name, and in the same context.

What it sounds like you're after is Devise's new Multi-User Models?

Alternatively, what you can do is keep your custom administration controllers in a different namespace (like Administration) and route /admin/buildings CRUD to a your custom namespace:

scope path: "/admin", as: "admin", module: 'administration' do
  resources :buildings
end

Upvotes: 2

Related Questions