当我尝试注册我的应用程序时,我不断收到此错误,我正在使用设计进行身份验证;
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 模型的设计代码中提供你的设计路线吗?
以下任一方法可能会解决您的问题:
<%= 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/