You probably want to use the select methods on the base connection,
rather than on any specific model. That returns an array of hashes of
column names and values.
Since you want a simple array in @dates, you could do this:
@dates = ActiveRecord::Base.connection.select_all("select DISTINCT
date_format(''%Y-%m-%d'',
created_on) as receipt_date from parts order by receipt_date").collect do
|row|
row["receipt_date"]
end
On 9/15/05, Chris Hall
<christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> What is the ''best practice'' for using custom forms that
don''t coincide
> with any particular model. ie, i need to create a form where the
> submitted data is then used to generate a list. obviously this form
> will not match any models so I''m not sure what the correct
procedure
> is to do this sort of thing and still be graceful.
>
> for example. say i have a parts table in the database.
>
> parts
> ----------
> id
> part_num
> part_desc
> part_qty
> created_on
> updated_on
>
> So as a user i go to myhost/app/parts/list and i''m shown a form
with a
> select field of dates based on the created_on field (say this
> represents the date the part was recieved in a warehouse). i select a
> date from the form, submit it and I am shown a list of all parts that
> were created on (received) on that date.
>
> Doing this (below) seems awkward as the information I am retrieving is
> not a part. it''s just an array of dates.
>
> @dates = Part.find_by_sql("select DISTINCT
date_format(''%Y-%m-%d'',
> created_on) as receipt_date from parts order by receipt_date")
>
>
> So do I need to create a "report" model/controller/view to do
this
> sort of thing?
>
> I think I''m not seeing the forest through the trees on this one.
>
> thanks for any insights.
>
> Chris
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>