代码之家  ›  专栏  ›  技术社区  ›  AlbertMunichMar

栏杆。具有2个用户模型的设计路由问题

  •  0
  • AlbertMunichMar  · 技术社区  · 7 年前

    我有两种模式,会计和客户。我想用designe做auth。我有以下配置:

    在路线中

    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
    

    会计.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
    

    会计/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
    

    关于如何调试这个有什么帮助吗?

    路线如下:

    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 回复  |  直到 7 年前
        1
  •  0
  •   Vishal    7 年前

    试着改变你的注册表格如下网址,让我知道如果它不工作

    <%= simple_form_for(resource, as: resource_name, url: account_registration_url(resource_name)) do |f| %>
    
        2
  •  0
  •   Siri Bunnamon    7 年前

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