gpt4 book ai didi

html - 在 Rails 简单表单中的编辑下拉列表中显示所选选项

转载 作者:行者123 更新时间:2023-11-28 01:29:35 25 4
gpt4 key购买 nike

我正在尝试使用 Rails 4 和简单的形式制作一个应用程序。

当我想编辑一个已保存的项目时,我会回到我的表单,该表单会显示原始问题,但没有在创建时选择输入。

有没有办法设置表单,以便在单击“编辑”时显示之前的选择?看来我还没有以显示编辑表单的方式选择输入。

例如,我的一个问题是:

<%= par.select :location,
options_for_select(["London", "Paris", "Berlin"]),
label: 'Where will participants take part in this project?',
prompt: "Choose one",
class: 'response-project' %>

当我在创建时选中 London 时,它会保存该选择。当我然后按编辑时,表单显示“选择一个”。看来我还没有拯救伦敦(我已经拯救了 - 数据库显示了那个选择)。

最佳答案

您可以尝试以下操作将当前位置设置为选定选项而不是提示选项:

options_for_select(["London", "Paris", "Berlin"], selected: :location)

关于html - 在 Rails 简单表单中的编辑下拉列表中显示所选选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30798951/

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