I've got some coffee script in /assets/javascripts/transactions.coffee
that populates a text field (in /views/transactions/_form.html.erb
) with today's date in dd/mm/yy
format.
$ ->
today = new Date
dd = today.getDate()
mm = today.getMonth() + 1
#January is 0!
yyyy = today.getFullYear()
if dd < 10
dd = '0' + dd
if mm < 10
mm = '0' + mm
today = dd + '/' + mm + '/' + yyyy
$('#transaction_date').val today
$ ->
$('#transaction_date').datepicker({dateFormat: "dd/mm/yy"})
Currently, that form is referenced in /views/transactions/new.html.erb
and /views/transactions/edit.html.erb
. However, I only want the text field to be populated on new.html.erb
and not edit.html.erb
.
What's the 'cleanest' way to achieve this in Rails (4.2.5)?