设计未定义的方法'registration_path'

时间:2017-08-23 22:16:17

标签: ruby-on-rails ruby devise

正在处理我的应用程序并安装和卸载几个宝石,然后突然设计的东西停止工作,我无法弄清楚为什么。我一直收到以下错误:

NoMethodError in Recipes#index
undefined method `registration_path' for #<#<Class:0x00560876ed7ef0>:0x00560876f06430>

它指的是我的注册和这段代码

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), validate: true) do |f| %>
                <%= devise_error_messages! %>
                <%= f.input :email, validate: true, required: true, placeholder: "Email", label: false %>
                <% if @minimum_password_length %>
                  <em>(<%= @minimum_password_length %> characters minimum)</em>
                <% end %>
                <%= f.input :password, autocomplete: "off", required: true, placeholder: "Password", label: false %>
                <%= f.input :password_confirmation, autocomplete: "off", required: true, placeholder: "Confirm Password", label: false %>
                <%= f.input :firstname, required: true, placeholder: "First Name", label: false %>
                <%= f.input :lastname, required: true, placeholder: "Last Name", label: false %>
                <%= f.input :displayname, validate: true, placeholder: "Display Name", label: false %>
                <div class="recaptcha">
                  <%= recaptcha_tags %>
                </div>
                <%= f.button :submit, "Sign up", class: 'btn btn-primary' %>
              <% end %>

在我的routes.rb中我有:

Rails.application.routes.draw do
  devise_for :users, controllers: { registrations: 'registrations', omniauth_callbacks: "callbacks" }

这是注册控制器:

class RegistrationsController < Devise::RegistrationsController

    def sign_up_params
        params.require(:user).permit(:firstname, :lastname, :displayname, 
                                     :email, :password, :password_confirmation)
    end

    def account_update_params
        params.require(:user).permit(:firstname, :lastname, :displayname,
                                     :email, :password, :password_confirmation)
    end

    def create
        if !verify_recaptcha
            flash.delete :recaptcha_error
            build_resource(sign_up_params)
            resource.valid?
            resource.errors.add(:base, "There was an error with the recaptcha code below. Please re-enter the code.")
            clean_up_passwords(resource)
            respond_with_navigational(resource) {render :new}
        else
            flash.delete :recaptcha_error
            super
        end
    end

    def after_inactive_sign_up_path_for(resource)
        '/pages/confirm_email'
    end
end

我在用户模型和控制器中有设计标准,并没有改变它们但它停止工作。不知道如何解决这个问题

编辑:rake路线显示注册路径不在那里由于某种原因:

                               Prefix Verb     URI Pattern                                                             Controller#Action
                          rails_admin          /admin                                                                  RailsAdmin::Engine
                     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_google_oauth2_omniauth_authorize GET|POST /users/auth/google_oauth2(.:format)                                     callbacks#passthru
 user_google_oauth2_omniauth_callback GET|POST /users/auth/google_oauth2/callback(.:format)                            callbacks#google_oauth2
     user_facebook_omniauth_authorize GET|POST /users/auth/facebook(.:format)                                          callbacks#passthru
      user_facebook_omniauth_callback GET|POST /users/auth/facebook/callback(.:format)                                 callbacks#facebook
                    new_user_password GET      /users/password/new(.:format)                                           devise/passwords#new
                   edit_user_password GET      /users/password/edit(.:format)                                          devise/passwords#edit
                        user_password PATCH    /users/password(.:format)                                               devise/passwords#update
                                      PUT      /users/password(.:format)                                               devise/passwords#update
                                      POST     /users/password(.:format)                                               devise/passwords#create
                new_user_confirmation GET      /users/confirmation/new(.:format)                                       devise/confirmations#new
                    user_confirmation GET      /users/confirmation(.:format)                                           devise/confirmations#show
                                      POST     /users/confirmation(.:format)                                           devise/confirmations#create

好的,所以这个错误令我感到困惑。我正在使用docker-compose进行开发,并且我重建了容器和图像。删除了所有内容并重新开始。设计注册设置中的某些东西搞砸了,不知道在哪里查看它是否正确。所以,当我去:localhost:8000/users/sign_in一切正常,它会进入设计登录页面......但是当我去localhost:8000/users/sign_up它说Couldn't find User with 'id'=sign_up。它就像devise_for:用户被注册的东西忽略了,不知道在哪里寻找那个因为宝石内部的东西...我想

4 个答案:

答案 0 :(得分:1)

我花了整整一天时间研究这个问题,发现一个愚蠢的错误。在我的设计模型(即Artist)中做其他工作时,我错误地从代码中删除了可注册

更改了代码
devise :database_authenticatable,
         :recoverable, :rememberable, :validatable

devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :validatable

答案 1 :(得分:1)

删除目录/ devise。然后重新运行rails生成devise:view 这对我有用。

答案 2 :(得分:0)

所以经过几个小时的挖掘,通过我的代码,与我的旧代码相比,并搜索设计和注册的每个组合,我可以想。我偶然发现了这个问题并且它很愚蠢...编辑我的User.rb模型的某个地方我意外删除了:可以从设计模块注册。这就是它没有产生注册路线的原因。所以修改了我的代码行:

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable,  :confirmable, 
       :recoverable, :rememberable, :trackable, :validatable,
       :omniauthable, omniauth_providers: [:google_oauth2, :facebook]

到此:

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :confirmable, 
       :recoverable, :rememberable, :trackable, :validatable,
       :omniauthable, omniauth_providers: [:google_oauth2, :facebook]

不知道在哪里或如何被删除但是它确实并且导致它在块的中间并没有注意到我正在查看我的代码

答案 3 :(得分:0)

也尝试重新启动服务器。

我的用户控制器中有 :registrable,但一直出现相同的错误。重新启动服务器帮助了我。