我有一个 email_address 对象,我正在尝试检查它是否在该特定域的黑名单上。我这样称呼它:
elsif @email.blacklisted?(@domain.id)
do something ...
end
我收到错误消息:
NoMethodError - undefined method `by_email' for ActiveModel::MassAssignmentSecurity::BlackList:Class:
我也尝试过使用 .find_all_by_id 而不是使用我创建的黑名单范围。虽然同样的错误。这让我发疯,任何想法都会很棒!
电子邮件地址类
class EmailAddress < ActiveRecord::Base
attr_accessible :email, :global_blacklist
has_many :transactions
has_many :black_lists
has_many :opt_outs
validates :email, :presence => true,
:uniqueness => true
validates :global_blacklist, :acceptance => true
def blacklisted?(domain_id)
black_lists = BlackList.by_email(self.id).by_domain(domain_id)
black_lists.count > 0
end
end
黑名单类
class BlackList < ActiveRecord::Base
attr_accessible :domain_id, :email_address_id, :date_added
belongs_to :domain
belongs_to :email_address
validates :domain_id, :presence => true
validates :email_address_id, :presence => true
validates :date_added, :presence => true
GLOBAL_BLACK_LIST_THRESHOLD = 2
scope :by_domain, ->(domain_id) { where('domain_id = ?', domain_id) }
scope :by_email, ->(email_id) { where('email_address_id = ?', email_id) }
end