简体   繁体   English

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

[英]Ruby on Rails - Devise sign up link not working - undefined method `user_registration_path'

This issue has been previously reported, but I still have not been able to find a fix for it. 此问题先前已报告过,但我仍无法找到解决方法。

I have installed the plugin Devise on to my new RoR project. 我已将插件Devise安装到我的新RoR项目中。 When I click on the sign up link, I am redirected to the following route: 当我点击注册链接时,我被重定向到以下路线:

http://localhost:3000/users/registration/sign_up HTTP://本地主机:3000 /用户/注册/ sign_up

However, I obtain the following error: 但是,我收到以下错误:

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

Extracted source (around line #5): 提取的来源(第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">

My routes produces the following: 我的路线产生以下内容:

    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

My routes.rb has the following code: 我的routes.rb具有以下代码:

 devise_for :users

  get "home/index"

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

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

UPDATED: I think you have to specify the "METHOD" as "POST" of the form. 更新:我认为您必须将“METHOD”指定为表单的“POST”。

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

================ (deprecated answer below) ================(以下弃用的答案)

I think you have problems in your config/routes.rb file. 我认为你的config / routes.rb文件有问题。 the expected output is : 预期的产出是:

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

so make sure your config/routes.rb has this linke of code: 所以请确保您的config / routes.rb具有以下代码:

devise_for :users

尝试这可能会有所帮助:如果你提到任何设计宝石版本删除它并保持只有宝石'设计'并在终端中键入捆绑更新命令。

This problem is created when the devise version is 1.1.0 RC and you are running Rails 3. 当设计版本为1.1.0 RC并且您正在运行Rails 3时,会创建此问题。

Please look on how to upgrade your devise gem: 请看看如何升级你的设计宝石:

https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0 https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM