Rails 4 选择不显示选择 [英] Rails 4 Select Not Displaying Selected
本文介绍了Rails 4 选择不显示选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个简短的.我有一个用于创建和编辑组的表单中的选择框.它有效,将选定的选项保存到数据库中,但表单不显示数据库中的内容,它始终显示第一个选项.
This is a short one. I have a select box that is in a form used to create and edit a group. It works, saves the selected option to the database, but the form does not display what is in the database, it always shows the first option.
<%= form_for @group, :html => {:multipart => true} do |f| %>
<%= f.select :privacy, options_for_select([["Public", "Public"], ["Private", "Private"]], @group.privacy), {}, {:class => 'form-control'} %>
<%= f.submit :class => 'btn btn-primary' %>
<% end %>
我也试过:
<%= f.select :privacy, options_for_select([["Public", "Public"], ["Private", "Private"]], :selected => @group.privacy), {}, {:class => 'form-control'} %>
同样,保存数据但不显示所选选项.
Again, that save the data but does not display the selected option.
感谢您提供的任何帮助.
Thanks for any help you can offer.
推荐答案
<%= f.select :privacy, options_for_select([["Public", "Public"], ["Private", "Private"]], :selected => f.object.privacy), {}, {:class => 'form-control'} %>
试试这个
这篇关于Rails 4 选择不显示选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文