2017-08-09 113 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再次爲您的答覆。但它仍然給我同樣的錯誤,不知道我在做什麼錯誤 –