简体   繁体   English

轨。 用于Devise的2个用户模型的路由问题

[英]Rails. Routing problem with 2 User models for Devise

I have two models, Accountant and Customer. 我有两个模型,会计和客户。 I want to do the auth with Devise. 我想用Devise进行身份验证。 I have following config: 我有以下配置:

In routes 在路线上

Rails.application.routes.draw do
  # devise_for :accountants, path: 'accountants'
  devise_for :accountants, path: 'accountants', controllers: { registrations: 'accountants/registrations', sessions: 'accountants/sessions' }

  root to: 'pages#home'
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

  get "registration", to: "pages#registration"
end

Accountant.rb Accountant.rb

class Accountant < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  belongs_to :company
end

accountants/new.html.erb 会计师/ new.html.erb

Sign up for accountants 注册会计师

<%= simple_form_for(resource, as: resource_name, url: accountant_registration_path) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :email,
                required: true,
                autofocus: true ,
                input_html: { autocomplete: "email" }%>
    <%= f.input :password,
                required: true,
                hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),
                input_html: { autocomplete: "new-password" } %>
    <%= f.input :password_confirmation,
                required: true,
                input_html: { autocomplete: "new-password" } %>
  </div>

  <div class="form-actions">
    <%= f.button :submit, "Sign up" %>
  </div>
<% end %>

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

I used: 我用了:

rails generate devise:controllers accountants

to create following controller 创建以下控制器

# frozen_string_literal: true

class Accountants::RegistrationsController < Devise::RegistrationsController
  # before_action :configure_sign_up_params, only: [:create]
  # before_action :configure_account_update_params, only: [:update]

  # GET /resource/sign_up
  def new
    super
  end

  # POST /resource
  def create
    super
  end

After hitting sign up, I am redirected to the /accountants url, where I see the sign up form, with the validation error. 点击注册后,我将重定向到/ accountants网址,在其中看到注册表单,并显示验证错误。 6 characters minimum (and the email is displayed), (I put a 6-character password). 最少6个字符(并显示电子邮件),(我输入了6个字符的密码)。

Any help on how to debug this? 任何有关如何调试的帮助?

The routes are as follow: 路线如下:

Prefix Verb   URI Pattern                                                                              Controller#Action
        new_accountant_session GET    /accountants/sign_in(.:format)                                                           accountants/sessions#new
            accountant_session POST   /accountants/sign_in(.:format)                                                           accountants/sessions#create
    destroy_accountant_session DELETE /accountants/sign_out(.:format)                                                          accountants/sessions#destroy
       new_accountant_password GET    /accountants/password/new(.:format)                                                      devise/passwords#new
      edit_accountant_password GET    /accountants/password/edit(.:format)                                                     devise/passwords#edit
           accountant_password PATCH  /accountants/password(.:format)                                                          devise/passwords#update
                               PUT    /accountants/password(.:format)                                                          devise/passwords#update
                               POST   /accountants/password(.:format)                                                          devise/passwords#create
cancel_accountant_registration GET    /accountants/cancel(.:format)                                                            accountants/registrations#cancel
   new_accountant_registration GET    /accountants/sign_up(.:format)                                                           accountants/registrations#new
  edit_accountant_registration GET    /accountants/edit(.:format)                                                              accountants/registrations#edit
       accountant_registration PATCH  /accountants(.:format)                                                                   accountants/registrations#update
                               PUT    /accountants(.:format)                                                                   accountants/registrations#update
                               DELETE /accountants(.:format)                                                                   accountants/registrations#destroy
                               POST   /accountants(.:format)                                                                   accountants/registrations#create
                          root GET    /                                                                                        pages#home
                  registration GET    /registration(.:format)                                                                  pages#registration

尝试更改您的注册表单的网址,如下所示,让我知道它是否不起作用

<%= simple_form_for(resource, as: resource_name, url: account_registration_url(resource_name)) do |f| %>

尝试更改注册表单的网址,如下所示:

<%= simple_form_for(resource, as: resource_name, url: accountant_registration_path) do |f| %>

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

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