Can rails formatting helpers be used on an ‘edit’ screen? The format helpers (number_to_currency, number_to_percent) are great for index/show, but I don’t see how to apply them during edit. I have a custom heler that formats the date:
def my_date_helper(datetime)
datetime.nil? ? "" : datetime.strf('%d-%b-%Y')
end
For example, if I have a starts_at attribute, that the user interacts with using a jQuery datepicker, the value placed in edit.html.erb in <%= f.text_field :starts_at %> by rails will be formatted like:
2011/12/19 00:00:00
I would like the user to be presented with a consistent format,so I want to apply the same format helper I use in show/index so the edit text field shows a format like:
19-Jan-2011
I just had a ‘duh’ moment. To doesn’t seem there’s any easy, rails-ey way. But it can be done really easy with unobtrusive JavaScript, like:
Four lines in
application.jsand you’re done.