The self
part is the problem, it is referencing the view itself* and that doesn't have a method called strftime
. You can fix it somewhat by doing
def nice_datetime(date)
date.strftime('...')
end
I would however urge you to look into localization.
Which would work something like this, just a very basic setup.
# config/locales/en.yml
en:
time:
formats:
short: "%H:%M"
<p><%= l Time.now, format: :short %></p>
* That might not be strictly true, I can't remember exactly how helpers are included in the view files, but for sake of this argument is close enough.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…