0
我有一個email_address對象,我試圖檢查它是否在特定域的黑名單上。我打電話這樣說:NoMethodError - 未定義的方法`by_email'ActiveModel :: MassAssignmentSecurity :: BlackList:Class:
elsif @email.blacklisted?(@domain.id)
do something ...
end
我收到錯誤:
NoMethodError - undefined method `by_email' for ActiveModel::MassAssignmentSecurity::BlackList:Class:
我也試圖做一個.find_all_by_id而不是使用我創建的黑名單範圍。雖然同樣的錯誤。這讓我瘋狂,任何想法都會很棒!
EmailAddress的類
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