High level overview:
I currently have a drop down menu in my view with multiple options for users
<%= f.select :carrier, options_for_select([["Select One", ""], "T-mobile", "Sprint",
"Virizon", "AT&T", "Tracphon", "U.S. Cellular", "Cricket"]), :class => 'genForm_dropBox'
%>
I'd like to update this dynamically by creating an carriers table so that I can loop through all carriers and add them to the dropdown without having to edit code to add carriers.
I've got a method in my controller
def craft
gateway_arry = Array.new
@carriers = Carrier.all
@carriers.each do |t|
gateway_arry << t.gateway
end
end
I'd like to iterate over this gateway_arry array in the view for select dropdowns. Is there a method for this in the view for select dropdowns ruby? If so what does it look like?
Thanks guys
还有collection_select
:
collection_select(:post, :id, Carrier.all, :id, :name)
You mean that ?
f.select :carrier,
options_for_select([["Select One", ""],
*Carrier.all.map(&:gateway)]),
:class => 'genForm_dropBox'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.