ruby-on-rails - 设计中没有方法错误::注册#new

标签 ruby-on-rails devise

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

    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

路由文件
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 和你的 User 模型的设计代码中提供你的设计路线吗?

以下任一方法可能会解决您的问题:

  • 重新启动 Rails 服务器。这样,Rails 将看到 Devise 对 Rails 所做的新文件和更改。
  • 您是否覆盖了 Devise::Registrations#new 操作?如果是这样,您需要替换下面的 View 代码:
  • <%= 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 View ,您的 form_for 代码如下所示:
    <%= form_for(resource, :as => resource_name, :url => edit_user_registration_path(resource_name, :method => :put) do |f| %>
    

    您的 rake routes实际上为您提供了您需要提交的路线。请记住,相应的 Controller 和 Action 显示在 rake routes 的输出中的 Controller#action 列下。 . edit中的表格操作应始终提交到 update Action 和表单 new操作应始终提交到 create如果您坚持 Rails 约定,请采取行动。如果您决定在另一个操作中使用表单来创建记录,请确保将表单提交到 create行动。

    关于ruby-on-rails - 设计中没有方法错误::注册#new,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20865184/

    相关文章:

    ruby-on-rails - 在本地计算机上模拟 Heroku

    ruby-on-rails - Facebook 登录 Devise Invitable

    ruby-on-rails - RSpec 测试 Devise Mailer

    ruby-on-rails - Ruby On Rails - 重写 devise_token_auth 中的渲染方法

    ruby-on-rails - ActiveRecord 查询用户所在时区的日期

    ruby-on-rails - Rails 两次发出相同的获取请求(更新 : only when I embed pinterest links on the page)

    ruby-on-rails - 更新 authlogic 不识别以前的旧密码

    ruby-on-rails - Devise登录后如何返回上一页

    ruby - 通过 ruby​​ 脚本设计身份验证

    ruby-on-rails - 在 simpleform + Rails 中的 bootstrap 中左对齐 "remember me"复选框