Devise_scope - 找不到路径的设计映射" /"

时间:2014-10-02 21:35:00

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

Could not find devise mapping for path "/". This may happen for two reasons: 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]

我试图去这里时遇到这个错误

http://localhost:3000/

以下是路线

  devise_scope :user do
     get '/users/sign_in' => 'devise/sessions#new', as: :new_user_session
     post   '/users/sign_in'  => 'devise/sessions#create',  as: :user_session
     delete '/users/sign_out' => 'devise/sessions#destroy', as: :destroy_user_session

     post  '/users/password'  => 'devise/passwords#create', as: :user_password
     put   '/users/password'  => 'devise/passwords#update', as: nil
     patch '/users/password'  => 'devise/passwords#update', as: nil
     authenticated :user do
        root :to => 'home#index', as: :authenticated_root
     end
     unauthenticated :user do
        root :to => 'devise/sessions#new', as: :unauthenticated_root
     end

  end

这个设置提前工作,所以我不知道它为什么会突然失败。关于我的设置的详细信息(来自内存):我做了

bundle install

设计作为宝石

rails g devise user

rails generate devise:views

我在development.rb

中添加了这一行
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

另外,我使用rails 4.2.0.beta1并设计3.3.0 pull from(git =&gt;'https://github.com/plataformatec/devise.git',: branch =&gt;'lm-rails-4-2')< / p>

2 个答案:

答案 0 :(得分:1)

尝试在范围块中编写路线。

devise_scope :user do
    # write all your routes inside this block
end

您可以在此处找到有关范围的更多信息

https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes

答案 1 :(得分:0)

我不知道你是否已找到答案,但我相信这就是你需要的......

它为我修复了此错误:stackoverflow question/answer