【问题标题】:Devise_scope - Could not find devise mapping for path "/"Devise_scope - 找不到路径“/”的设计映射
【发布时间】:2014-10-02 21:35:00
【问题描述】:
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 并设计从 (git => 'https://github.com/plataformatec/devise.git', :branch => 'lm-rails-4-2') 提取的 3.3.0

【问题讨论】:

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


    【解决方案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

    【讨论】:

    • 代码示例在devise_scope 块中包含路由。
    猜你喜欢
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多