如何添加下拉菜单<选项>在轨道形式? [英] How to add a dropdown <option> in a rails form?
本文介绍了如何添加下拉菜单<选项>在轨道形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个脚手架 -
I had created a scaffold-
rails g scaffold shipment name:string description:text from:string to:string date:string pay:string
我想要 form:string
是一个下拉菜单(加尔各答/德里/孟买为选项),而不是文本字段。我怎么做到这一点?
I want the form:string
to be a drop down (with Kolkata/Delhi/Mumbai as options) and not a text field. How can I do this?
我曾经在网上搜索过,但一切都过于上层。
I had searched the web but everything was too upper level. I am new to Rails and am trying to learn this.
推荐答案
您可以在 app \views\shipments\_form.html.erb
file
you can use the select helper in your app\views\shipments\_form.html.erb
file
<%= form_for(@shipment) do |f| %>
<%= f.label :from %><br>
<%= f.select :from, [ 'Kolkata','Delhi','Mumbai' ], :prompt => 'Select One' %>
<%= f.submit %>
<% end %>
这篇关于如何添加下拉菜单<选项>在轨道形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文