Is there an easy way to format the display of a DateTime value in a Rails view?
For example, if I\'m doing something like:
<%= text_field
In a helper
def l(value, options = {})
return nil unless value.present?
value = value.to_date if value.is_a? String
super(value, options)
end
Then in the view
<%= f.text_field :end_date, class: "datepicker" :value => l(@activity.end_date) %>
Here l is a rails helper (I18n.l) which can be locale specific and can take a format. Examples:
l(@activity.end_date, format: :short)
l(@activity.end_date, format: "%d-%m-%Y")