Search code examples
ruby-on-railsrubyroutes

Uninitialized constant Admin::Admin


Using Ruby: 2.3.1p112 and Rails: 3.2.12

I'm trying call a demo method in my controller. So, in my _form.html.erb I have:

<%= link_to 'Demo', "/admin/clinics/"[email protected]_s+"/demo" %>

In my routes.rb:

match "/admin" => "admin#index", :as => :admin

namespace :admin do
    resources :admin_users
    resources :health_plan_tables
    resources :health_aid_tables
    resources :clients
    resources :clinics
    resources :specialties
    resources :qualifications
    resources :profissionals
    resources :addresses
    resources :documents
    resources :banners
    root :to => 'banners#index'
    get 'logout' => 'devise/sessions#destroy'

    get 'clinics/:id/demo', to: 'admin/clinics#demo', as: 'demo'
end

My clinics_controller.rb is inside the folder controllers/admin, and I just have:

def demo
    print "hello"
end 

So, when I click on link, error message appears Uninitialized constant Admin::Admin. Any ideia how to fix it?


Solution

  • Since you are already defining your demo route inside a namespace there is no need to specify admin/clinics#demo, just clinics#demo will be necessary:

    namespace :admin do
        resources :admin_users
        resources :health_plan_tables
        resources :health_aid_tables
        resources :clients
        resources :clinics
        resources :specialties
        resources :qualifications
        resources :profissionals
        resources :addresses
        resources :documents
        resources :banners
        root :to => 'banners#index'
        get 'logout' => 'devise/sessions#destroy'
    
        get 'clinics/:id/demo', to: 'clinics#demo', as: 'demo'
    end