2013-03-26 37 views
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 

回答

0

以防萬一任何人有這個問題...

類的名字黑名單(國會L)似乎是一個加載ActiveModel班級名稱。

我將類名更改爲黑名單(一個字而不是兩個),問題就消失了。

相關問題