Select Box not filling properly in rails
Posted
by CaptnCraig
on Stack Overflow
See other posts from Stack Overflow
or by CaptnCraig
Published on 2010-04-13T00:28:02Z
Indexed on
2010/04/13
0:32 UTC
Read the original article
Hit count: 413
I am creating a select box for a form using this in _form.html.erb
<%= f.select(:category_id,options_for_select(@cats)) %>
@cats is an array created in my controller like this:
@cats = []
categories.each do |c|
@cats.push([c.full_name,c.id])
end
The select box is properly filled, and the selected foreign key is even properly saved to the database. The problem is, when I come back in my edit action, the select box is moved back to the first item in the list, not the one corresponding to category_id. Reading the documentation it seems like this should just magically work. How do I get it to select the proper value?
© Stack Overflow or respective owner