我有以下型号:
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 :(得分:2)
FileInfo::STATUS
访问哈希本身,它是一个类方法,所以在类上调用它。