将包括范围在内的多个值添加到 rails select 下拉列表
Add multiple values including a range to a rails select dropdown
我的 rails 应用程序中有一个下拉菜单,我希望用户能够从一系列数字中 select 以及值“仍在参加”。
谁能帮我解决这个问题。我的范围工作正常但是当我添加
, "Still Attending"
它停止工作了。
<%= select(:year, '', options_for_select(2021.downto(1950), "Still Attending"), { prompt: "Select Year" }, class: "input border border-grey-light text-sm mt-2 w-full") %>
假设您希望“Still Attenting”成为首选,您可以将其设为选项数组中的第一个元素。
<%= select(:year, '', options_for_select(["Still Attending"] + 2021.downto(1950).to_a), { prompt: "Select Year" }, class: "input border border-grey-light text-sm mt-2 w-full") %>
options_for_select中的第二个参数只是设置当前“选中”的选项,它本身并不是一个新选项。
我的 rails 应用程序中有一个下拉菜单,我希望用户能够从一系列数字中 select 以及值“仍在参加”。
谁能帮我解决这个问题。我的范围工作正常但是当我添加
, "Still Attending"
它停止工作了。
<%= select(:year, '', options_for_select(2021.downto(1950), "Still Attending"), { prompt: "Select Year" }, class: "input border border-grey-light text-sm mt-2 w-full") %>
假设您希望“Still Attenting”成为首选,您可以将其设为选项数组中的第一个元素。
<%= select(:year, '', options_for_select(["Still Attending"] + 2021.downto(1950).to_a), { prompt: "Select Year" }, class: "input border border-grey-light text-sm mt-2 w-full") %>
options_for_select中的第二个参数只是设置当前“选中”的选项,它本身并不是一个新选项。