All I want to do is find the objects that were created today under the
'created_on' column. I've tried many ways, here is one example using
the chronic gem.
hmm. None of the suggestions worked. I just created some new objects
so the created_on date should be set to today. I also changed it to
Product.find(:all) and its passing through to my view okay. All of the
suggestions rendered an empty unordered list in my view, which I'm
guessing means empty array.
Where to show the number that have been updated today, I call this as:
<%= "(#{pluralize Product.count_recent(Time.now.seconds_since_midnight), 'product'} today)" %>
In your case, perhaps this:
@products = Product.find_all_by_created_on(Time.now.beginning_of_day())
Or if your database timestamps are UTC:
@products = Product.find_all_by_created_on(Time.now.utc.beginning_of_day())
I tend to use the created_at rather than created_on, but I think this would work for you.
This is driving me absolutely nuts! Thanks for the reply Rob. In AWDwR
it says "Rails applications conventionally use the _on suffix for date
columns and the _at suffix for columns that include time." Date and
time is what I want so I changed the column to created_at and
restarted the server. I also changed my controller and view to reflect
'created_at' but I still keep getting the same problem. I can find the
objects if I just use Object.find(:all) but any of the other
suggestions returns an empty arrray. I've made sure the objects were
created today. I'm guessing that the dates in my controller and in the
database are just not aligning up. Thanks for the help so far.
Here is my code:
Controller ---
def index
@products =
Product.find_all_by_created_at(Time.now.beginning_of_day())
respond_to do |format|
format.html # index.rhtml
end
end
View ---
<ul>
<% for product in @products %>
<li>
<%= product.created_at %>
</li>
<% end %>
</ul>
My model and view has nothing special in it that would conflict with
this.
This is driving me absolutely nuts! Thanks for the reply Rob. In AWDwR
it says "Rails applications conventionally use the _on suffix for date
columns and the _at suffix for columns that include time." Date and
time is what I want so I changed the column to created_at and
restarted the server. I also changed my controller and view to reflect
'created_at' but I still keep getting the same problem. I can find the
objects if I just use Object.find(:all) but any of the other
suggestions returns an empty arrray. I've made sure the objects were
created today. I'm guessing that the dates in my controller and in the
database are just not aligning up. Thanks for the help so far.
Here is my code:
Controller ---
def index
@products =
Product.find_all_by_created_at(Time.now.beginning_of_day())