I have a view of my model with many date fields rendered.
What I want to do is call strftime('%d.%m.%Y %H:%M')
on each date field I have.
- @items.each do |item|
= item.date_field.strftime('%d.%m.%Y %H:%M')
= item.date_field1.strftime('%d.%m.%Y %H:%M')
Any ideas on how I can to DRY this? I tried to make to_s
method in my model, but unfortunately that doesn't work.
Update:
I defined this method:
def to_s(date)
send(date).strftime('%d.%m.%Y %H:%M')
end
So I can:
- @items.each do |item|
= item.to_s(:date_field)
= item.to_s(:date_field1)