【问题标题】:Proper way of rails routing custom Users controller and devise gemrails路由自定义用户控制器和设计gem的正确方法
【发布时间】:2015-03-24 01:50:12
【问题描述】:

我在路由我的自定义用户控制器和设计 gem 时遇到问题。 当我尝试联系http://localhost:3000/users

<%= link_to 'Users', users_path, class: 'navbar-brand' %>

我得到错误:

    Could not find devise mapping for path "/users". 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]

如果我运行命令 rake routes 我会得到这个输出:

 Prefix Verb   URI Pattern                       Controller#Action
                    root GET    /                                 static_pages#home
        new_user_session GET    /users/sign_in(.:format)          devise/sessions#new
            user_session POST   /users/sign_in(.:format)          devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)         devise/sessions#destroy
           user_password POST   /users/password(.:format)         devise/passwords#create
       new_user_password GET    /users/password/new(.:format)     devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)    devise/passwords#edit
                         PATCH  /users/password(.:format)         devise/passwords#update
                         PUT    /users/password(.:format)         devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)           devise/registrations#cancel
       user_registration POST   /users(.:format)                  devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)          devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)             devise/registrations#edit
                         PATCH  /users(.:format)                  devise/registrations#update
                         PUT    /users(.:format)                  devise/registrations#update
                         DELETE /users(.:format)                  devise/registrations#destroy
       user_confirmation POST   /users/confirmation(.:format)     devise/confirmations#create
   new_user_confirmation GET    /users/confirmation/new(.:format) devise/confirmations#new
                         GET    /users/confirmation(.:format)     devise/confirmations#show
                   users GET    /users(.:format)                  users#index
                         POST   /users(.:format)                  users#create
                new_user GET    /users/new(.:format)              users#new
               edit_user GET    /users/:id/edit(.:format)         users#edit
                    user GET    /users/:id(.:format)              users#show
                         PATCH  /users/:id(.:format)              users#update
                         PUT    /users/:id(.:format)              users#update
                         DELETE /users/:id(.:format)              users#destroy
          account_update PATCH  /account_update(.:format)         users#update

这是我的路线

  root 'static_pages#home'

  devise_for :users

  resources :users
  as :user do
    patch 'account_update' => 'users#update'
    get 'users' => 'users#index'
  end

如何告诉 Rails 在 /users 上应该转到控制器用户并选择索引页面

【问题讨论】:

  • 你能试试吗,比如 devise_scope :user do
  • 天哪,它正在工作!
  • @amtest 将其发布为答案 :-) 和包点..

标签: ruby-on-rails ruby devise


【解决方案1】:

你可以试试这样的,

devise_for :users

devise_scope :user do

end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 2012-06-19
    • 1970-01-01
    相关资源
    最近更新 更多