Ruby on Rails - 设计注册链接无效 - 未定义方法`user_registration_path'

时间:2012-03-18 22:30:59

标签: ruby-on-rails devise

此问题之前已有过报道,但我仍无法找到解决方法。

我已将插件Devise安装到我的新RoR项目中。当我点击注册链接时,我被重定向到以下路线:

http://localhost:3000/users/registration/sign_up

但是,我收到以下错误:

undefined method `user_registration_path' for #<#<Class:0x007fd5d3503d58>:0x007fd5d3b0dcd0>

提取的来源(第5行):

2:   <h1>Sign up</h1>
3: </div>
4: 
5: <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
6:   <%= f.error_notification %>
7: 
8:   <div class="inputs">

我的路线产生以下内容:

    new_user_session GET    /users/sign_in(.:format)              devise/sessions#new
        user_session POST   /users/sign_in(.:format)              devise/sessions#create
destroy_user_session GET    /users/sign_out(.:format)             devise/sessions#destroy
            password POST   /users/password(.:format)             devise/passwords#create {:name_prefix=>:user}
        new_password GET    /users/password/new(.:format)         devise/passwords#new {:name_prefix=>:user}
       edit_password GET    /users/password/edit(.:format)        devise/passwords#edit {:name_prefix=>:user}
                     PUT    /users/password(.:format)             devise/passwords#update {:name_prefix=>:user}
                     POST   /users/registration(.:format)         devise/registrations#create {:name_prefix=>"user_registration"}
                 new GET    /users/registration/sign_up(.:format) devise/registrations#new {:name_prefix=>"user_registration"}
                edit GET    /users/registration/edit(.:format)    devise/registrations#edit {:name_prefix=>"user_registration"}
                     PUT    /users/registration(.:format)         devise/registrations#update {:name_prefix=>"user_registration"}
                     DELETE /users/registration(.:format)         devise/registrations#destroy {:name_prefix=>"user_registration"}
          home_index GET    /home/index(.:format)                 home#index
               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
                     PUT    /users/:id(.:format)                  users#update
                     DELETE /users/:id(.:format)                  users#destroy
                root        /                                     home#index

我的routes.rb包含以下代码:

 devise_for :users

  get "home/index"

  resources :users
  root :to => "home#index"

3 个答案:

答案 0 :(得分:11)

我有这个问题并重新启动rails服务器为我修复了

答案 1 :(得分:1)

更新:我认为您必须将“METHOD”指定为表单的“POST”。

5: <%= simple_form_for(resource, :as => resource_name, 
6:    :url => registration_path(resource_name), 
7:    :method => :POST) do |f| %>

================(以下弃用的答案)

我认为你的config / routes.rb文件有问题。预期的产出是:

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

所以请确保你的config / routes.rb有这个代码链接:

devise_for :users

答案 2 :(得分:0)

试试这可能会有所帮助: 如果你提到任何设计宝石版本删除它并且只保留gem'devise'并在终端中输入bundle update命令。