简体   繁体   中英

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. 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. So I give this example to illustrate drop down menu for select temperature. 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 %>

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.

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