Ruby on Rails Wednesday, September 1, 2010

Hello and thanks for taking the time to read this,

last night I came across two problems from which the first one - I am
sure - is easy to solve. But as I am a beginner I am unable to find the
solution.

As I learned through the night rails stores created_at dates in utc.
Sure enough my local time zone is not utc :-)
When I have an item and use the method created_at rails translates the
time to my local time zone.

So when I add an item at 0:15 am local time and want to list all the
items for today with

@items = Item.find(:all, :conditions => [ "created_at LIKE ?",
"#{Time.now.to_date}%" ])

this item will never be found as its created_at date is yesterday. My
first idea was to add 7200 two created_at in the find clause, but that
would be an ugly workaround (I even did not get that to work...).

Can You tell me what would be the correct solution to translate?

And now the second question: Is there (already) a best practice to query
this in rails 3? I didn't find a solution to do a "LIKE" query without a
plugin, so how can one get all items created today out of the database?

@orders = Order.where(:created_at.to_date => Time.now.to_date) does not
work as I cannot add the method to_date to a symbol.

Thank You all
greetings
Sven
--
Posted via http://www.ruby-forum.com/.

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment