2017-07-18 45 views
-1

使用Ruby:2.3.1p112和Rails:3.2.12

未初始化的不断联系::管理

我想呼吁在我的控制器演示方法。所以,在我_form.html.erb我:

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

在我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 

clinics_controller.rb是文件夹controllers/admin里面,我只是有:

def demo 
    print "hello" 
end 

所以,当我点击链接,出现错误信息Uninitialized constant Admin::Admin。 任何ideia如何解决它?

+0

你可以发布完整的错误stacktrace? – Pavan

+0

在这里男人:[链接](https://uploaddeimagens.com.br/imagens/image-png--479) –

回答

1

既然您已经定义命名空间中的demo路线没有必要指定admin/clinics#demo,只是clinics#demo将是必要的:

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 
+0

我得到'Missing template admin'错误。 [退房](https://uploaddeimagens.com.br/imagens/image2-png--14)。 –

+2

@ThiagoAnderson这是因为在app/views/admin/clinics中你没有一个叫'demo.html.erb'的视图;您必须添加该模板。或者,如果您只想在浏览器中打印“hello”,则将“print”hello“'更改为'inline:”hello“'。 – Gerry

+1

好@Gerry!而已。谢谢! –

1

根据错误日志,你正在寻找一个控制器命名空间下管理员/管理员/诊所(它说,在PARAMS的控制器部分)。

更改底部路线不包括管理员(它已经命名空间,你就有效的命名空间两次):

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

这将路由到正确的控制器,管理员/诊所,而不是管理员/管理员/诊所

+0

我得到了'Missing template admin'错误。 [退房](https://uploaddeimagens.com.br/imagens/image2-png--14)。 –

+1

我会把这个留给Gerry。 – Mark

+0

Ohh:/刚注意到我们在同一时间回答(实际上我在1分钟后)。 – Gerry

相关问题