user3752649
user3752649

Reputation: 67

Accessing a hash from one model class to other in RoR

I have the following model:

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

I want to access STATUS hashmap in another class:

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

How do I do that?

Upvotes: 0

Views: 25

Answers (1)

Matt
Matt

Reputation: 14038

FileInfo::STATUS to access the hash itself, it's a class method so call it on the class.

Upvotes: 2

Related Questions