Rails.Проблема маршрутизации с 2 пользовательскими моделями для Devise - PullRequest
0 голосов
/ 24 сентября 2018

У меня есть две модели: бухгалтер и клиент.Я хочу сделать авторизацию с Devise.У меня есть следующий конфиг:

На маршрутах

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

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

Подписаться набухгалтеры

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

Я использовал:

rails generate devise:controllers accountants

для создания следующего контроллера

# 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

После нажатия я перенаправлен на URL / accountants, гдеЯ вижу форму регистрации с ошибкой проверки.Минимум 6 символов (и отображается электронная почта), (я поставил 6-значный пароль).

Любая помощь о том, как отладить это?

Маршруты следующие:

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

Ответы [ 2 ]

0 голосов
/ 24 сентября 2018

Попробуйте изменить URL для формы регистрации, как показано ниже:

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

0 голосов
/ 24 сентября 2018

попробуйте изменить URL для вашей формы регистрации, как показано ниже, дайте мне знать, если она не работает

<%= simple_form_for(resource, as: resource_name, url: account_registration_url(resource_name)) do |f| %>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...