简体   繁体   中英

Rails created_at on display if Today?

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')

Maybe a helper ...

def created_at_for_view k
   k.created_at if k.created_at.to_date == Date.today
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM