Heesob Park
9/11/2008 1:18:00 AM
Hi,
2008/9/11 Allen Walker <auswalk@gmail.com>:
> 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