From: Heesob Park Date: 2008-09-11T10:17:47+09:00 Subject: Re: Getting values from array of arrays Hi, 2008/9/11 Allen Walker : > I have a drop down list in my view. In my model I have the following: > > ARTICLE_CATEGORIES = [ > ["News", 1], ["Article", 2], ["Review", 3] > ] > > validates_inclusion_of :category, :in => ARTICLE_CATEGORIES.map { |disp, > value| value } > > I want to extract out all "Article" types in my controller. > > So in my controller: (I have a 'category' field in my 'articles' table) > > @news = Article.find_by_category(ARTICLE::ARTICLE_CATEGORIES.find...??) > > Not sure how to do this. I want to get the ID (in this case 2) from the > ARTICLES_CATEGORIES array but I want to extract it out of this array > using the key "Article". > You can use assoc like this: id = ARTICLE_CATEGORIES.assoc("Article").last Regards, Park Heesob