如何下拉< select>栏位栏位? [英] How to have a drop down <select> field in a rails form?

查看:128
本文介绍了如何下拉< select>栏位栏位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个脚手架 -

I am creating a scaffold -

rails g scaffold Contact email:string email_provider:string 

但是我希望电子邮件提供者是一个下拉菜单(使用gmail / yahoo / msn作为选项),而不是文本字段。我该怎么做?

but I want the email provider to be a drop down (with gmail/yahoo/msn as options) and not a text field. How can I do this ?

推荐答案

你可以看一下 Rails文档。无论如何,您的形式:

You can take a look at the Rails documentation . Anyways , in your form :

  <%= f.collection_select :provider_id, Provider.order(:name),:id,:name, include_blank: true %>

您可以猜测,您应该在另一个模型中预定义电子邮件提供商 - 提供者,以便从中选择它们。

As you can guess , you should predefine email-providers in another model -Provider , to have where to select them from .

这篇关于如何下拉&lt; select&gt;栏位栏位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆