【问题标题】:No route matches [POST] "/users/sign_up.user"没有路线匹配 [POST] "/users/sign_up.user"
【发布时间】:2016-11-10 17:54:38
【问题描述】:

我在我的用户模型中加入了设计,但是当我尝试注册某人时,我收到此错误 No route matches [POST] "/users/sign_up.user" 我的应用程序中也有设计视图和控制器。但是当我点击注册按钮时,我得到了那个错误。

这是我的 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

这是我的表格

注册

<%= 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" %>

【问题讨论】:

  • 请发布您的路线和表格代码。
  • 您的注册表单看起来有错误的网址。

标签: ruby-on-rails devise


【解决方案1】:

我也遇到了同样的问题,并且为所发生的事情苦苦挣扎了一段时间。我的解决方案可能与您的特定情况无关,但值得一试。

在我看来,我曾使用 erb 的 button_to 标签来点击 new_user_registration_path

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

当路由是 GET 请求时,这是发送 POST 请求。将button_to 标记更改为link_to 标记解决了它:

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

【讨论】:

    【解决方案2】:

    由于您将路线更改为:

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

    您在表单中使用的路径中不需要资源。只需将其取出,它应该如下所示:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 2012-07-22
      • 1970-01-01
      相关资源
      最近更新 更多