Constants in model

Hi,

I have a constant in Model like;

class Post < ActiveRecord::Base

STATES = {:id => 100, :status => “public”},
{:id => 110, :status => “protected”},
{:id => 120, :status => “private”},
{:id => 130, :status => “deleted”}
end

And i write a method to find elements in that STATES constant

class Post < ActiveRecord::Base

def self.find_state(key, value)
Post::STATES.collect { |state| return state if state[:"#{key}"] ==
value }
end
end

When I write Post.find_state(‘status’, ‘private’) it brings me back
that hash and i get id with the symbol of [:id].

How can I improve this? Could i use it like “Post::STATES.find(:id =>
120)” or something else? or Could i use it in a named_scope like
“named_scope :status”?

I need your advices.

Thanks


Mehmet Davut
davit~
www.mehmetdavut.com.tr
0532 224 93 65