Re: find_by_sql timestamp parameter

Frederick Cheung
Tue, 25 May 2010 10:33:37 -0000

On May 25, 9:29 am, Stanislav Orlenko
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:
> Hi
> In controller I have this query:
>
> @price_stat = Price.find_by_sql("select id, cost, tour_id,
> unix_timestamp(created_at) from prices")
>
> when I try to display result''s created_at column I don''t
have any
> results:
>
> <% @price_stat.each do |p| %>
> <%= p.created_at %>
> <% end %>
>

> result is empty

Because created_at is no longer in the select list - some column with
a different name is there instead. You should probably to something
like unix_timestamp(created_at) as unix_created_at in your select
clause (and then p.unix_created_at should be that value)

Fred

--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at