Simm Simm - 1 year ago 100
Ruby Question

if statement using created_at

<% if product.created_at %>
<span class="label label-warning">New!</span>
<% end%>

Web dev newbie.. Can't figure out how to use if statement in rails view to display the span class when product records is up to 3 days old. Any ideas?

I can query in my console with

variable = Product.where(created_at:

and get the the correct records. But cannot understand how to translate this into rails.

The ERB block is going into a _partial

dkp dkp
Answer Source

You can try this:

<% if product.created_at > 3.days.ago.beginning_of_day %>
  <span class="label label-warning">New!</span>
<% end%>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download