2014-06-30 25 views
0

我有以下型号:访问从一个模型类散到其他RoR中

class FileInfo < ActiveRecord::Base 
    STATUS = {:UNAPPROVED => 1, :APPROVED => 2, :PROCESSED => 3 } 
    attr_accessible :id, :status 
    validates :status, :inclusion => {:in => STATUS.values}  
end 

我要访问STATUS HashMap的另一个类:

class FileInfoObserver < ActiveRecord::Observer 
    def after_save(file_info)   
    if file_info.status.eql? 2 //HERE, I want to access STATUS[:APPROVED] 
     // Some logic  
    end 
    end 
end 

我该怎么办呢?

+0

尝试FileInfo :: STATUS [@ m.column_name] –

回答

2

FileInfo::STATUS要访问哈希本身,它是一个类方法,所以在类上调用它。