2017-08-09 117 views
0

我在routes.rb中找不到设计映射路径

devise_for :users, controllers: { registrations: "network/registrations",sessions: 'network/sessions', passwords: 'network/passwords' } 


devise_scope :user do 
    get "registrations/show" => "network/registrations", as: :show_user_profile 
end 

定义了以下路线,当我做耙路线我也看到

network_show_user_profile GET /network/registrations/show(.:format)                network/registrations#show 

但是,当我试图访问路径/网络/注册/节目

我得到下面的异常

找不到设计映射路径“/ network/registrations/show”。 可能发生这种情况的原因有两个:

1) You forgot to wrap your route inside the scope block. For example: 

    devise_scope :user do 
    get "/some/route" => "some_devise_controller" 
    end 

2) You are testing a Devise controller bypassing the router. 
    If so, you can explicitly tell Devise which mapping to use: 

    @request.env["devise.mapping"] = Devise.mappings[:user] 

我试图修改routes.rb中,并加入

devise_scope :user do 
    get 'user_profile' => 'registrations#search', :as => 'user_profile' 
end 

,当我访问user_profile路,我得到的错误

The action 'show' could not be found for Network::RegistrationsController 

但当我添加动作显示到控制器我再次得到相同的异常消息

无法找到路径“/ network/registrations/show”的设计映射。 可能发生这种情况的原因有两个:

1) You forgot to wrap your route inside the scope block. For example: 

    devise_scope :user do 
    get "/some/route" => "some_devise_controller" 
    end 

2) You are testing a Devise controller bypassing the router. 
    If so, you can explicitly tell Devise which mapping to use: 

    @request.env["devise.mapping"] = Devise.mappings[:user] 

任何帮助,以什么我做错了,将不胜感激。谢谢。

回答

0

我想补充说,你做了

Rails.application.routes.draw do 

    devise_for :users, controllers: { registrations: "network/registrations",sessions: 'network/sessions', passwords: 'network/passwords' } 


    devise_scope :user do 
    get "registrations/show" => "network/registrations", as: :show_user_profile 
    end 
end 

走相同的路线,但不是

network_show_user_profile GET /network/registrations/show(.:format)

show_user_profile GET /registrations/show(.:format) registrations#show

所以我换成这个路线有以下

Rails.application.routes.draw do 

    devise_for :users, controllers: { registrations: "network/registrations",sessions: 'network/sessions', passwords: 'network/passwords' } 


    devise_scope :user do 
    get "/network/registrations/show" => "network/registrations#show", as: :show_user_profile 
    end 
end 
文件

我也​​创建一个动作show

一切正常完美的我。

希望这会有所帮助。

+0

嗨nimish,仍然是同样的错误。 –

+0

@ opensource-developer请参阅最新的答案 –

+0

嗨@nimish再次为您的答复。但它仍然给我同样的错误,不知道我在做什么错误 –