gpt4 book ai didi

ruby-on-rails - 编辑表单时显示所选选项 (Rails 4)

转载 作者:行者123 更新时间:2023-12-04 10:50:00 25 4
gpt4 key购买 nike

我想在用户编辑表单时显示我的下拉表单选择选项值。现在它显示第一个选项(在本例中为空白选项)。

表格

<%= f.select(:condition, options_for_select([["Brand New", "Brand New"], ["Pre-owned", "Pre-owned"]]), :include_blank => true, :selected => params[:condition]) %>

HTML 输出
<select id="product_condition" name="product[condition]">
<option value=""></option>
<option value="Brand New">Brand New</option>
<option value="Pre-owned">Pre-owned</option>
</select>

JSON
{
id: 2,
condition: "Pre-owned",
}

谢谢。

最佳答案

<%= f.select(:condition, options_for_select([["Brand New", "Brand New"], ["Pre-owned", "Pre-owned"]], :selected => f.object.condition), :include_blank => true) %>

关于ruby-on-rails - 编辑表单时显示所选选项 (Rails 4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28286761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com