简体   繁体   English

没有路由与[POST]“ /users/sign_up.user”匹配

[英]No route matches [POST] “/users/sign_up.user”

I incorporated devise in my user model but when i try to sign up someone i get this error No route matches [POST] "/users/sign_up.user" I have the devise views and controllers in my app too. 我在用户模型中加入了devise,但是当我尝试注册某人时出现此错误,没有路由与[POST]“ /users/sign_up.user”相匹配,我的应用程序中也有devise视图和控制器。 But when i click the sign up button i get that error. 但是,当我单击“注册”按钮时,出现该错误。

this is my routes.rb 这是我的routes.rb

Rails.application.routes.draw do
  devise_for :users, controllers: { registrations: "users/registrations" }

  #resources :users  

  #resources :admin

  devise_scope :user do
    root :to => 'devise/sessions#new'
  end
end

and this is my form 这是我的表格

Sign up 注册

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

  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, autofocus: true %>
  </div>

  <div class="field">
    <%= f.label :password %>
    <% if @validatable %>
    <em>(<%= @minimum_password_length %> characters minimum)</em>
    <% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
  </div>

  <div class="field">
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, autocomplete: "off" %>
  </div>

  <div class="actions">
    <%= f.submit "Sign up" %>
  </div>
<% end %>

<%= render "users/shared/links" %>

I had this exact same problem, and struggled with what was up for a while. 我也遇到了同样的问题,并在一段时间内苦苦挣扎。 My solution might not have anything to do with your particular case, but worth a try. 我的解决方案可能与您的特定情况无关,但值得一试。

In my view I had used erb's button_to tag to hit the new_user_registration_path : 在我看来,我曾使用erb的button_to标记来点击new_user_registration_path

<%= button_to 'Sign up', new_user_registration_path %>

this was sending a POST request when the route is a GET request. 当路由是GET请求时,它正在发送POST请求。 Changing the button_to tag to a link_to tag solved it: button_to标签更改为link_to标签可以解决该问题:

<%= link_to 'Sign up', new_user_registration_path %>

Since you changed the route to: 由于您将路线更改为:

devise_for :users, controllers: { registrations: "users/registrations" }

There's no need for the resource in the path you're using in your form. 在表单中使用的路径中不需要资源。 Simply take it out and it should look like this: 只需将其取出,它应如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM