我有两个模型,会计和客户。我想用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
点击注册后,我被重定向到/ accountants url,在其中看到注册表单,并显示验证错误。最少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
答案 0 :(得分:0)
尝试更改您的注册表单的网址,如下所示,让我知道它是否无效
<%= simple_form_for(resource, as: resource_name, url: account_registration_url(resource_name)) do |f| %>
答案 1 :(得分:0)
尝试更改注册表单的网址,如下所示:
<%= simple_form_for(resource, as: resource_name, url: accountant_registration_path) do |f| %>