You may need to alter this a little, if I''ve guessed wrong about the
format you want in your dropdown list.
def build_list_thingy
entries = ActiveRecord::Base.connection.select_all("select distinct
month(created_at) as month,year(created_at) as year from articles
order by years,months").collect do |row|
row["month"] + ''/'' + row["year"]
end
entries.zip(entries) # You want this because options_for_select is
expecting an array of arrays.
end
Then just do
@whatever_options = build_list_thingy, and use @whatever_options in
your select() tag.
On 9/28/05, Matt Pantana
<matt.pantana-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I have an Article model. The article has a created_at field. I''m
trying to
> generate two lists of dates to filter search results. So, I''m
looking for a
> list of months and years articles have been entered...like so:
>
> select distinct month(created_at) as months,year(created_at) as years from
> articles order by years,months
>
> How do I put this in an object and use it to populate a dropdown list?
I''m
> not sure how to use ActiveRecord outside the traditional Object=>Table
> model.
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>