当我尝试注册我的应用程序时,我一直收到此错误,我正在使用设计进行身份验证;
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 />
当我运行rake routes
时,我得到了;
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
注册链接代码;
<%= link_to "Sign up", new_user_registration_path%>
更新 感谢ParaPenguin,注册字段现在可以正常工作,但是当我点击提交时,我不断遇到这个问题
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)
更新2-Gjaldon要求我包含我的用户模型和路线 我的用户模型
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"
答案 0 :(得分:6)
您可以在routes.rb中提供Devise的路线以及您的用户模型的设计代码吗?
以下任一项可能会解决您的问题:
重新启动Rails服务器。这样,Rails就会看到新文件和Devise对Rails所做的更改。
您是否覆盖了Devise :: Registrations#new action?如果是这样,您需要更换以下视图代码:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
使用:
<%= form_for(resource, :as => resource_name, :url => user_registration_path) do |f| %>
在devise_registrations/edit.html.erb
视图中,您的form_for代码如下所示:
<%= form_for(resource, :as => resource_name, :url => edit_user_registration_path(resource_name, :method => :put) do |f| %>
您的rake routes
实际上为您提供了您需要提交的路线。请记住,相应的控制器和操作显示在rake routes
输出中的Controller#action列下。 edit
操作中的表单应始终提交到update
操作,如果您坚持使用Rails约定,则new
操作中的表单应始终提交到create
操作。如果您决定在另一个操作中创建表单以创建记录,请确保将表单提交给create
操作。
答案 1 :(得分:0)
尝试从
更改registration_path(resource_name)
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
到new_registration_path(resource_name)
。这可以解决错误,但我不确定,这是可能的。它似乎只适合你,因为文件设置对我的设计来说运行得很好。