DRi*_*ing 5 ruby ruby-on-rails devise
正在开发我的应用程序并安装和卸载一些宝石,然后突然设计的东西停止工作,我不明白为什么。我不断收到以下错误:
NoMethodError in Recipes#index
undefined method `registration_path' for #<#<Class:0x00560876ed7ef0>:0x00560876f06430>
Run Code Online (Sandbox Code Playgroud)
它指的是我的注册和这段代码
<%= 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 %>
Run Code Online (Sandbox Code Playgroud)
在我的routes.rb中我有这个:
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: 'registrations', omniauth_callbacks: "callbacks" }
Run Code Online (Sandbox Code Playgroud)
这是注册控制器:
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
Run Code Online (Sandbox Code Playgroud)
我在用户模型和控制器中拥有标准的设计内容,它们没有任何变化,但它停止工作。不知道如何解决这个问题
编辑: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
Run Code Online (Sandbox Code Playgroud)
好吧,这个错误让我感到困惑。我正在使用 docker-compose 进行开发,并重建了容器和图像。删除所有内容并重新开始。设备的注册设置中的某些内容被搞乱了,不知道在哪里查看它是否正确。因此,当我转到:localhost:8000/users/sign_in一切正常,并且转到设备登录页面时...但是当我转到它时localhost:8000/users/sign_up,它说Couldn't find User with 'id'=sign_up. 就像 devise_for :用户在注册时被忽略,并且不确定在哪里寻找该原因,这都是宝石内部的......我认为
因此,经过几个小时的挖掘我的代码,与我的旧代码进行比较并谷歌搜索我能想到的设计和注册的每种组合。我偶然发现了这个问题,这很愚蠢......在编辑我的 User.rb 模型时,我不小心从设计模块中删除了 :registable 。这就是为什么它没有生成注册路由。所以修复了我的代码行:
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]
Run Code Online (Sandbox Code Playgroud)
对此:
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]
Run Code Online (Sandbox Code Playgroud)
不确定它在哪里或如何被删除,但它确实被删除了,因为它位于块的中间,当我查看我的代码时没有注意到
| 归档时间: |
|
| 查看次数: |
2932 次 |
| 最近记录: |