大佬教程收集整理的这篇文章主要介绍了ruby-on-rails-3 – 使用rails 3中的devise和acts_as_tenant的用户的唯一性,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我只为租户设置了用户模型和帐户模型.
我可以针对多个租户@R_467_10589@ – 这一切都正常工作除了当我尝试使用相同的电子邮件创建两个用户对不同的租户ID时,我得到了一个单一性错误.
我正在使用所述的validates_uniqueness_to_tenant选项.
用户模型
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable,:confirmable,# :lockable,:timeoutable and :omniauthable devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable attr_accessible :email,:password,:password_confirmation,:remember_me acts_as_tenant(:account) validates_uniqueness_to_tenant :email end
帐户模型
class Account < ActiveRecord::Base attr_accessible :name end
应用控制器
class ApplicationController < ActionController::Base set_current_tenanT_By_subdomain(:account,:subdomain) protect_from_forgery end
看起来它应该基于acts_as_tenant中的所有文档工作,我是否需要在设计级别覆盖某些内容?
编辑:经过一些头疼和一点休息后,问题是我相信,因为默认情况下,Devise为电子邮件列添加了一个唯一索引.
这显然不会影响act_as_tenant想要做的事情……
我会尝试删除索引,看看Devise是否呕吐.
编辑2:好的,现在已经正式放弃了.我对主站点进行了手动滚动身份验证,这与acts_as_tenant一起正常运行.
我只能假设在某个层面上acts_as_tenant和Devise之间存在一些不兼容性 – 除了我在这个阶段找到它.
class User < ActiveRecord::Base acts_as_tenant :account attr_accessible :email,:remember_me #remove :validatable devise :database_authenticatable,:trackable #run own validations #I've omitted any emailformatTing checks for clarity's sake. validates :email,presence: true,uniqueness: { scope: :account_id,case_sensitive: false } validates :password,length: { :in => 6..20 },:if => :password_required? protected # copied from validatable module def password_required? !persisted? || !password.nil? || !password_confirmation.nil? end end
以上是大佬教程为你收集整理的ruby-on-rails-3 – 使用rails 3中的devise和acts_as_tenant的用户的唯一性全部内容,希望文章能够帮你解决ruby-on-rails-3 – 使用rails 3中的devise和acts_as_tenant的用户的唯一性所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。