简体   繁体   English

如何将元素添加到 Rails 的下拉列表中?

[英]How can i add elements into drop down list in rails?

I want to add drop down list with my own values.我想用我自己的值添加下拉列表。 According to the given drop down list value i am going to do a search particular data.根据给定的下拉列表值,我将搜索特定数据。 My drop down list should be contained trainer, venue, name and date.我的下拉列表应包含培训师、场地、姓名和日期。

I am working on ruby 1.9.2 and rails 2.3.8 versions and postgresql database adapter.我正在研究 ruby 1.9.2 和 rails 2.3.8 版本以及 postgresql 数据库适配器。 I do not need to retrieve data from database.我不需要从数据库中检索数据。 Drop down list should be contained with my given vales.下拉列表应包含在我给定的值中。 How can i do this?我怎样才能做到这一点? Anybody plz help me....任何人请帮助我....

You can simply add element as follows您可以简单地添加元素如下

Hear I assume there is a model call Entry and it contain two field call:name and:temperature.听说我假设有一个 model 调用条目,它包含两个字段调用:名称和:温度。 So I give this example to illustrate drop down menu for select temperature.所以我举这个例子来说明 select 温度的下拉菜单。 It may have three values (Hot,Medium,Cold) and this is how we have to write the code它可能有三个值(热、中、冷),这就是我们编写代码的方式

<% form_for @entry do |f| %>
  <%= f.text_field :name %>
  <%= f.select :temperature, [['Hot','hot'],['Medium','medium'],['Cold','cold']] %>
  <%= f.submit %>
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM