Have have this line of code in my form when I create a new item. Though when I edit the item, the default selection isn’t the one that is selected. Do I need to set the initial value?
<%= f.select :category, options_for_select(Item::CATEGORIES) %>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
options_for_selectaccepts second param which identifies the selected value.try
It assumes your
Item::CATEGORIESgives a array of strings of categories.for each category in
Item::CATEGORIES,category.downcasewill be used as the option’s value, whilecategory.titleizewill be used as the option’s text.ie.
======
or you could: