0
呈现的HTML:select_tag options_for_select,默认值没有得到设置
<select id="version_filter" name="version_filter">
<option value="2">Current Version</option>
<option value="1">1</option>
<option value="0">0</option>
</select>
通过警报到我的网页的select_tag
<%= select_tag "version_filter",
options_for_select(@version_select, @selected_version.to_s) %>
我看是否@selected_version甚至存在:
alert("<%= @selected_version.to_s %>");
它确实。 @selected_version是0,但是当页面加载时,下拉选择事件显示“当前版本”作为选定的值。
Rails并没有抱怨语法,所以,我怎样才能得到默认选择的第一个值?
是version_select'整数或字符串在'@值?如果它们的值比'@ selected_version'的字符串值不相等。 –
@version_select是一个2d的整数数组。我会尝试删除.to_s UPDATE:没有工作,行为与问题相同。 – NullVoxPopuli
更新2:事实证明我必须做.to_i o.o – NullVoxPopuli