# Trying to make an app helper

**URL:** <https://www.ruby-forum.com/t/trying-to-make-an-app-helper/50618>\
**Category:** Rails\
**Created:** [December 19, 2005, 7:12am UTC](https://www.ruby-forum.com/t/trying-to-make-an-app-helper/50618 "2005-12-19T07:12:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 19, 2005, 7:12am UTC](https://www.ruby-forum.com/t/trying-to-make-an-app-helper/50618/1 "2005-12-19T07:12:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 19, 2005, 7:14am UTC](https://www.ruby-forum.com/t/trying-to-make-an-app-helper/50618/2 "2005-12-19T07:14:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 19, 2005, 7:18am UTC](https://www.ruby-forum.com/t/trying-to-make-an-app-helper/50618/3 "2005-12-19T07:18:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 19, 2005, 11:02pm UTC](https://www.ruby-forum.com/t/trying-to-make-an-app-helper/50618/4 "2005-12-19T23:02:18Z")

</div>

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…
