无法找到路径的设计映射

时间:2017-08-09 16:46:10

标签: ruby ruby-on-rails-4 devise

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

当我做rake路线时,我也看到了

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

但是当我尝试访问路径/ 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]

任何关于我做错的帮助都将不胜感激。感谢。

1 个答案:

答案 0 :(得分: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

中创建了一个动作network/registrations_controller.rb

一切都适合我。

希望这有帮助。