[英]Is there a method for iterating over an array in the view for select dropdowns ruby
高級概述:
我目前在視圖中有一個下拉菜單,其中有多個用戶選項
<%= f.select :carrier, options_for_select([["Select One", ""], "T-mobile", "Sprint",
"Virizon", "AT&T", "Tracphon", "U.S. Cellular", "Cricket"]), :class => 'genForm_dropBox'
%>
我想通過創建一個載具表來動態更新此表,以便我可以遍歷所有載具並將其添加到下拉列表中,而無需編輯代碼來添加載具。
我的控制器中有一個方法
def craft
gateway_arry = Array.new
@carriers = Carrier.all
@carriers.each do |t|
gateway_arry << t.gateway
end
end
我想遍歷視圖中的gateway_arry數組以選擇下拉列表。 在視圖中是否存在用於選擇下拉列表紅寶石的方法? 如果是這樣,它是什么樣的?
多謝你們
還有collection_select
:
collection_select(:post, :id, Carrier.all, :id, :name)
你的意思是?
f.select :carrier,
options_for_select([["Select One", ""],
*Carrier.all.map(&:gateway)]),
:class => 'genForm_dropBox'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.