我的应用程序具有用户模型,角色模型和分配模型。通过分配模型,用户和角色模型之间存在多对多的关系。我想检查当前用户是否具有特定的role_id。能做到这一点吗?
我的模型课如下
class User < ActiveRecord::Base
has_many :assignments
has_many :roles, :through => :assignments
end
class Assignment < ActiveRecord::Base
belongs_to :user
belongs_to :role
end
class Role < ActiveRecord::Base
has_many :assignments
has_many :users, :through => :assignments
end
current_user.role_ids.include?(role_id)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句