Rails 3 集合,选择选择如何在编辑时显示正确的值



我的编辑表单中有一个选择列表,我想看到为我正在编辑的人选择正确的种族

<%= simple_nested_form_for @person do |f| %>
  <%= f.input :first_name %>
  <%= f.input :last_name %>
  <%= f.input :ethnicity,
                collection: Person.select('distinct ethnicity'),
                :label_method =>  :ethnicity,
                :input_html => {:class => 'chosen-select'} %> 
<input type="submit" value="Update Person" name="commit" class="btn-edit">
<% end %>    

人.rb

class Person < ActiveRecord::Base
   attr_accessible  :ethnicity, :description, :first_name, :last_name   

我想要在编辑时选择的种族的正确值。我该怎么做?
对于我所做的,当我在编辑页面上时,我没有种族值

为选择列表设置value_method,如下所示:

<%= f.input :ethnicity,
                collection: Person.select('distinct ethnicity'),
                :label_method =>  :ethnicity,
                :value_method =>  :ethnicity,    
                :input_html => {:class => 'chosen-select'} %> 

最新更新