Devise中的NoMethodError ::注册#new [英] NoMethodError in Devise::Registrations#new
问题描述
NoMethodError在Devise ::注册#new
未定义的方法#registration_path为#<#<类:0x007fe45c6c35e8>:0x007fe45d9ffd78>
提取源(绕行#3):
< h2>注册< / h2>
<%= form_for(resource,:as => resource_name,:url => registration_path(resource_name))do | f | %GT;
<%= devise_error_messages! %GT;
< div><%= f.label:email%>< br />
当我运行 rake路由
前缀动词URI模式控制器#动作
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_password POST / users /密码(。:格式)devise / passwords#create
new_user_password GET /users/password/new(.:format)devise / passwords#new
edit_user_password GET /users/password/edit(.:format)设计/密码#编辑
PATCH /users/password(.:format)devise / passwords#update
PUT /users/password(.:format)devise / passwords#update
cancel_user_registration GET /用户/取消(。:格式)设计/注册#取消
user_registration POST /users(.:format)设计/注册#create
new_user_registration GET /users/sign_up(.:format)设计/注册#new
edit_user_registration GET / users / edit(编辑
PATCH /users(.:format)设计/注册#update
PUT /users(.:format)设计/注册#update
DELETE / users (。:格式)设计/注册#destroy
注册链接代码;
<%= link_to注册,new_user_registration_path%>
更新
感谢ParaPenguin注册字段现在工作,但是当我点击提交我不断得到这个问题
没有路由匹配[POST]/ users / sign_up
new_user_session_path GET /users/sign_in(.:format)devise / sessions#new
user_session_path POST /users/sign_in(.:format)devise / sessions#create
destroy_user_session_path DELETE / users / create_out(。:format)devise / sessions#destroy
user_password_path POST /users/password(.:format)devise / passwords#create
new_user_password_path GET /users/password/new(.:format)devise /密码#新
edit_user_password_path GET /users/password/edit(.:format)devise / passwords#edit
PATCH /users/password(.:format)devise / passwords#update
PUT / users / password(。:format)devise / passwords#update
cancel_user_registration_path GET /users/cancel(.:format)设计/注册#cancel
user_registration_path POST /users(.:format)设计/注册#create
new_user_registration_path GET /users/sign_up(.:format)设计/注册#new
edit_user_registration_path GET / users / edit (。:format)设计/注册#编辑
PATCH /users(.:format)设计/注册#update
PUT /users(.:format)设计/注册#update
DELETE /用户(。:格式)
更新2-Gjaldon要求我添加我的用户模型和路线
我的用户模型
class User< ActiveRecord :: Base
#包含默认设计模块。其他可用的是:
#:confirmable,:lockedable,:timeoutable和:omniauthable
devise:database_authenticatable,:可注册,
:可恢复,可记忆,可追溯,可验证
结束
Routes.rb
Document :: Application.routes.draw do
devise_for:users
rootpages#home
getabout=> page#about
getprices=> pages#prices
getfaq=> page#faq,:as => :faq
getterms=> pages#terms
getview=> pages#view
getpolicy=> pages#policy
getcontact=> pages#contact
getworks=> page#works
设计您的路线和您的用户模型的设计代码?
以下可能会解决您的问题:
-
重新启动Rails服务器。这样,Rails将会看到Devise已经对Rails做出的新文件和更改。
-
你是否覆盖了Devise ::注册#新操作?如果是这样,您将需要更换下面的视图代码:
<%= form_for(resource,:as => resource_name,:url => registration_path(resource_name))do | f | %>
with:
<%= form_for(resource,:as => resource_name,:url => user_registration_path)do | f | %GT;
在您的 devise_registrations / edit.html.erb
view,您的form_for代码将如下所示:
<%= form_for(resource,:as => resource_name, url => edit_user_registration_path(resource_name,:method =>:put)do | f |%>
您的 rake路线
实际上为您提供了您需要提交的路线。请记住,相应的控制器和操作显示在控制器#操作列中 rake路线的输出
。编辑
操作中的表单应始终提交给更新
操作和
新表单
操作应始终提交到创建
操作,如果您坚持Rails约定如果您决定在创建记录的另一个操作中使用表单,请确保将表单提交到创建
操作。
I keep getting this error when I try to sign up on my application, I am using devise for authentication;
NoMethodError in Devise::Registrations#new
undefined method `registration_path' for #<#<Class:0x007fe45c6c35e8>:0x007fe45d9ffd78>
Extracted source (around line #3):
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
When I run rake routes
I get;
Prefix Verb URI Pattern Controller#Action
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_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
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
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
Sign up link code;
<%= link_to "Sign up", new_user_registration_path%>
UPDATE Thanks to ParaPenguin the sign up field works now, but when I click submit I keep getting this problem
No route matches [POST] "/users/sign_up"
new_user_session_path GET /users/sign_in(.:format) devise/sessions#new
user_session_path POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session_path DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password_path POST /users/password(.:format) devise/passwords#create
new_user_password_path GET /users/password/new(.:format) devise/passwords#new
edit_user_password_path GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration_path GET /users/cancel(.:format) devise/registrations#cancel
user_registration_path POST /users(.:format) devise/registrations#create
new_user_registration_path GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration_path GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format)
Update 2-Gjaldon asked me to include my user model and routes My user model
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
Routes.rb
Document::Application.routes.draw do
devise_for :users
root "pages#home"
get "about" => "pages#about"
get "prices" => "pages#prices"
get "faq" => "pages#faq", :as => :faq
get "terms" => "pages#terms"
get "view" => "pages#view"
get "policy" => "pages#policy"
get "contact" => "pages#contact"
get "works" => "pages#works"
Could you provide your routes for Devise in your routes.rb and the devise code for your User model?
It's either one of the following that might fix your problem:
Restart your Rails server. This way, Rails will see the new files and changes Devise has made to Rails.
Did you override the Devise::Registrations#new action? If so, you will need to replace your view code below:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
with:
<%= form_for(resource, :as => resource_name, :url => user_registration_path) do |f| %>
In your devise_registrations/edit.html.erb
view, your form_for code would look like:
<%= form_for(resource, :as => resource_name, :url => edit_user_registration_path(resource_name, :method => :put) do |f| %>
Your rake routes
actually provides you with the routes you need to submit to. Just keep in mind that the corresponding controller and action is displayed under the Controller#action column in the output of rake routes
. The form in edit
action should always submit to the update
action and the form in new
action should always submit to the create
action if you stick to the Rails conventions. If you decide to have a form in another action for creating a record, then make sure to have the form submit to the create
action.
这篇关于Devise中的NoMethodError ::注册#new的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!