当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - How can i get separate tables for manager , owner , visitor as i am using rolify gem?

问题描述:

I am new to stackoverflow and i want to implement user with multiple roles .

I had started with rolify gem . I had generated 3 devise users manager , owner , user (visitor).

Association used for my application is

class Role < ApplicationRecord

has_and_belongs_to_many :users, :join_table => :users_roles

belongs_to :resource,

:polymorphic => true,

:optional => true

validates :resource_type,

:inclusion => { :in => Rolify.resource_types },

:allow_nil => true

scopify

end


class User < ApplicationRecord

rolify

# Include default devise modules. Others available are:

# :confirmable, :lockable, :timeoutable and :omniauthable

devise :database_authenticatable, :registerable,

:recoverable, :rememberable, :trackable, :validatable

after_create :assign_default_role

def assign_default_role

self.add_role(:visitor) if self.roles.blank?

end

end


class Owner < User

# Include default devise modules. Others available are:

# :confirmable, :lockable, :timeoutable and :omniauthable

devise :database_authenticatable, :registerable,

:recoverable, :rememberable, :trackable, :validatable

after_create :assign_default_role

def assign_default_role

self.add_role(:owner) if self.roles.blank?

end

end


class Manager < User

# Include default devise modules. Others available are:

# :confirmable, :lockable, :timeoutable and :omniauthable

devise :database_authenticatable, :registerable,

:recoverable, :rememberable, :trackable, :validatable

after_create :assign_default_role

def assign_default_role

self.add_role(:moderator) if self.roles.blank?

end

end


My concern is i am using rolify gem to assign role but i want to keep manager , owner , visitor table separate but if i didn't use Single table inheritance then how can i able to implement roles and keep table separate


分享给朋友:
您可能感兴趣的文章:
随机阅读: