Когда я пытаюсь создать или войти в систему и создать пользователя, чаще всего выдают эту ошибку.
Сначала я создаю пользователя модели, а перед администратором модели
user.rb
class User < ActiveRecord::Base
has_many :transactions
belongs_to :admin
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
extend Devise::Models # Fix error undefined method `devise'
# for User (call 'User.connection' to establish a connection):Class
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
include DeviseTokenAuth::Concerns::User
end
admin.rb
# frozen_string_literal: true
class Admin < ActiveRecord::Base
has_many :users
has_many :transactions
has_many :beneficiaries
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
extend Devise::Models # Fix error undefined method `devise'
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
include DeviseTokenAuth::Concerns::User
end
route.rb
# frozen_string_literal: true
Rails.application.routes.draw do
mount_devise_token_auth_for 'User', at: 'auth'
mount_devise_token_auth_for 'Admin', at: 'admin_auth'
# as :admin do
# # Define routes for Admin within this block.
# end
root 'main#index'
resources :beneficiaries, only: %i[index create update destroy]
resources :transactions, only: %i[index create update destroy]
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
Я не могу только войти и создать администратора, но пользователь выдает эту ошибку.
DeviseTokenAuth::Errors::InvalidModel (Cannot set auth token in invalid model. Errors: ["Role must exist", "Admin must exist"]):
devise_token_auth (1.1.3) app/controllers/devise_token_auth/concerns/set_user_by_token.rb:109:in `update_auth_header'