Devise中的NoMethodError :: Registrations #new

当我尝试注册我的应用程序时,我一直收到此错误,我正在使用设计进行身份validation;

NoMethodError in Devise::Registrations#new undefined method `registration_path' for #<#:0x007fe45d9ffd78> Extracted source (around line #3): 

Sign up

resource_name, :url => registration_path(resource_name)) do |f| %>

当我跑到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 

注册链接代码;

  

更新感谢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" 

您能否在routes.rb中提供Devise的路线以及用户模型的设计代码?

它可能是以下哪种方法可以解决您的问题:

  1. 重新启动Rails服务器。 这样,Rails将看到Devise对Rails所做的新文件和更改。

  2. 你是否覆盖了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操作。

尝试更改registration_path(resource_name)

 <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 

new_registration_path(resource_name) 。 这可以解决错误,但我不确定,这是可能的。 它似乎只适合你,因为文件设置运行正好适用于我的设计。