- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正在开发我的应用程序并安装和卸载几个 gem,然后突然设计的东西停止工作,我不知道为什么。我不断收到以下错误:
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" }
这是注册 Controller :
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
我在用户模型和 Controller 中有标准的设计东西,它们没有任何改变,但它停止了工作。不知道如何解决这个问题
编辑: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 :users 被忽略了注册的东西,不知道在哪里寻找那个原因这都是 gem 内部的......我认为
最佳答案
因此,经过数小时挖掘我的代码,与我的旧代码进行比较并在谷歌上搜索我能想到的所有设计和注册组合。我偶然发现了这个问题,这很愚蠢......在编辑我的 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]
到这个:
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]
不确定在哪里或如何被删除,但它确实被删除了,因为我在查看我的代码时没有注意到它位于 block 的中间
关于ruby-on-rails - 设计未定义的方法 'registration_path',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45850112/
我想了解 Ruby 方法 methods() 是如何工作的。 我尝试使用“ruby 方法”在 Google 上搜索,但这不是我需要的。 我也看过 ruby-doc.org,但我没有找到这种方法。
Test 方法 对指定的字符串执行一个正则表达式搜索,并返回一个 Boolean 值指示是否找到匹配的模式。 object.Test(string) 参数 object 必选项。总是一个
Replace 方法 替换在正则表达式查找中找到的文本。 object.Replace(string1, string2) 参数 object 必选项。总是一个 RegExp 对象的名称。
Raise 方法 生成运行时错误 object.Raise(number, source, description, helpfile, helpcontext) 参数 object 应为
Execute 方法 对指定的字符串执行正则表达式搜索。 object.Execute(string) 参数 object 必选项。总是一个 RegExp 对象的名称。 string
Clear 方法 清除 Err 对象的所有属性设置。 object.Clear object 应为 Err 对象的名称。 说明 在错误处理后,使用 Clear 显式地清除 Err 对象。此
CopyFile 方法 将一个或多个文件从某位置复制到另一位置。 object.CopyFile source, destination[, overwrite] 参数 object 必选
Copy 方法 将指定的文件或文件夹从某位置复制到另一位置。 object.Copy destination[, overwrite] 参数 object 必选项。应为 File 或 F
Close 方法 关闭打开的 TextStream 文件。 object.Close object 应为 TextStream 对象的名称。 说明 下面例子举例说明如何使用 Close 方
BuildPath 方法 向现有路径后添加名称。 object.BuildPath(path, name) 参数 object 必选项。应为 FileSystemObject 对象的名称
GetFolder 方法 返回与指定的路径中某文件夹相应的 Folder 对象。 object.GetFolder(folderspec) 参数 object 必选项。应为 FileSy
GetFileName 方法 返回指定路径(不是指定驱动器路径部分)的最后一个文件或文件夹。 object.GetFileName(pathspec) 参数 object 必选项。应为
GetFile 方法 返回与指定路径中某文件相应的 File 对象。 object.GetFile(filespec) 参数 object 必选项。应为 FileSystemObject
GetExtensionName 方法 返回字符串,该字符串包含路径最后一个组成部分的扩展名。 object.GetExtensionName(path) 参数 object 必选项。应
GetDriveName 方法 返回包含指定路径中驱动器名的字符串。 object.GetDriveName(path) 参数 object 必选项。应为 FileSystemObjec
GetDrive 方法 返回与指定的路径中驱动器相对应的 Drive 对象。 object.GetDrive drivespec 参数 object 必选项。应为 FileSystemO
GetBaseName 方法 返回字符串,其中包含文件的基本名 (不带扩展名), 或者提供的路径说明中的文件夹。 object.GetBaseName(path) 参数 object 必
GetAbsolutePathName 方法 从提供的指定路径中返回完整且含义明确的路径。 object.GetAbsolutePathName(pathspec) 参数 object
FolderExists 方法 如果指定的文件夹存在,则返回 True;否则返回 False。 object.FolderExists(folderspec) 参数 object 必选项
FileExists 方法 如果指定的文件存在返回 True;否则返回 False。 object.FileExists(filespec) 参数 object 必选项。应为 FileS
我是一名优秀的程序员,十分优秀!