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 << "<option value=''" << curmonth << "'' selected=''selected''>" << month << "</option>" else o << "<option value=''" << curmonth << "'' selected=''selected''>" << month << "</option>" end curmonth = curmonth + 1 end o end end -- Posted via http://www.ruby-forum.com/.
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 -- Posted via http://www.ruby-forum.com/.
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 On 12/19/05, Chris Hulbert <chris.hulbert-gR5rH3iIA/qLnZed9OPc8Q@public.gmane.org> wrote:> 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 << "<option value=''" << curmonth << "'' selected=''selected''>" << > month << "</option>" > else > o << "<option value=''" << curmonth << "'' selected=''selected''>" << > month << "</option>" > end > curmonth = curmonth + 1 > end > o > end > end > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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... -- Posted via http://www.ruby-forum.com/.