Trying to make an app helper

Any ideas with fixing this? Doesn’t work properly, although it doesn’t
throw any runtime errors.

Methods added to this helper will be available to all templates in the

application.
module ApplicationHelper
def options_for_months(selected_month)
months=[“January”,“February”,“March”,“April”,“May”,“June”,“July”,“August”,“September”,“October”,“November”,“December”]
curmonth=1
o=""
months.each do |month|
if curmonth == selected_month
o << “” <<
month << “”
else
o << “” <<
month << “”
end
curmonth = curmonth + 1
end
o
end
end

Other than the obvious ‘selected=selected’ on both the true and false
sides of the if statement, of course…

I seem to find that the option value=‘X’ - the X is gibberish, it should
be 1…12

Hi Chris –

It looks like you have the HTML “selected” attribute set in both the
IF and ELSE (which would cause the first month in the list to always
be selected in the dropdown box.)

Hope that helps,
EJC

Solved it. I just needed to add the to_s to the curmonth, to convert it
from an int to a string (i would have thought that was automatic?) :
<< curmonth.to_s <<

And of course the ‘selected’ on both sides of the if statement, but it
took me 5 seconds to realise that…