Rails created_at on display if today?

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

<%=h k.created_at %>

Is it possible? Or should it be done in the controller, not in the view?

Thank,

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')
+3
source share
1 answer

Perhaps helper...

def created_at_for_view k
   k.created_at if k.created_at.to_date == Date.today
end
+6
source

Source: https://habr.com/ru/post/1749820/


All Articles