开发者

Select Box not filling properly in rails

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 c开发者_如何学编程ontroller 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?


When you use the select helper you just pass the choices not the full option tags like you would with the select_tag helper. Try this instead

<%= f.select(:category_id, @cats) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜