My question is similar to Rails – return an array of months for a select tag.
But I want an array like this:
[
["September", 9],
["August", 8],
["July", 7],
["June", 6],
["May", 5],
["April", 4],
["March", 3],
["February", 2],
["January", 1],
["December", 0]
["November", -1],
["October", -2]
]
And if the current month were October, it would be:
[
["October", 10]
["September", 9],
["August", 8],
["July", 7],
["June", 6],
["May", 5],
["April", 4],
["March", 3],
["February", 2],
["January", 1],
["December", 0]
["November", -1]
]
This should do it:
Edit:
As you mentioned in a comment you wanted to display the year, you need a different approach to “go back in time”. As you are using rails, you can use activerecord’s date functions to do that: