views:

32

answers:

1

Hi Everyone,

Is it possible to display the created_at date, only if that date matches today's date?

<%=h k.created_at %>

Is this possible? Or should it be done in the controller rather than the view?

Thanks,

Danny

I have the following in my environment.rb:

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(:default => '%d/%m/%Y')
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:default => '%d/%m/%Y')
+1  A: 

Maybe a helper...

def created_at_for_view k
   k.created_at if k.created_at.to_date == Date.today
end
j.
Am I right in thinking once that helpers in kases_helper.rb, I should be able to call it using <%=h k.created_at_for_view %> ?
dannymcc
You should call `created_at_for_view(k)`
j.
That doesn't result in any errors - but doesnt display anything either. :(
dannymcc
It's creating the empty span so I presume it's just not finding anything to return. Could this be because I have altered the date format in the environment.rb? I have updated my question with my alterations.
dannymcc
Not sure. I edited my answer, added a `to_date`... I believe it may work now.
j.
Great, works a treat! Thanks.
dannymcc
Nice... Glad it helped. You should accept the answer then :]
j.