如何在Edit Ruby on Rails中显示记录的值

时间:2013-07-16 21:07:21

标签: ruby-on-rails ruby-on-rails-3

我有一个主要细节工作,但当我转到编辑表单时,选择字段未显示为数据库中记录的,它显示第一个option_for_select

<div class='fields'>
  <div class='span-24 last'>
    <div class='span-11'>
      <%= f.select :ordem, options_for_select([["0", 0], ["1", 1], ["2", 2], ["3", 3], ["4", 4], ["5", 5]]) %>
    </div>
    <div class='span-8'><%= f.text_field :opcao %></div>

    <div class='last'>
      <%= f.hidden_field :_destroy %>  
      <%= link_to_function '(X)', "remove_fields(this)" %>
    </div>
  </div>
</div>

那么我该如何显示此选择的录制内容呢?

1 个答案:

答案 0 :(得分:1)

只需添加一个包含选项ID的:selected选项即可:

f.select :ordem, [["0", 0], ["1", 1]], {:selected => '1'}