Rails 5.1
Devise
Devise Invitable
在models / concerns / shared.rb中,我有:
module Shared
extend ActiveSupport::Concern
def generate_model_id
self.id = "#{self.class.name}.#{Time.now.to_f.to_s}" if id.blank?
end
在我的create_usres迁移文件中,我有:
class DeviseCreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users, id: false do |t|
t.column :id, :primary_string
在我的models / user.rb中,我有:
class User < ActiveRecord::Base
include Shared
enum role: [:user, :vip, :admin]
after_initialize :set_default_role, :if => :new_record?
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
在我的seeds.rb文件中,我有:
user = User.new(
:email =>'myemail@mydomain.com',
:password =>'xK#986754',
:password_confirmation =>'xK#986754',
:first_name =>'John',
:last_name =>'Doe',
:role => 1,
:approved => true
)
user.skip_invitation
user.save
我已导出所有Devise模型(确认,邀请,密码,注册,会话,解锁),并将相应的控制器放在controllers / users文件夹下。
我从哪个控制器调用generate_model_id方法?