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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to