0

I have a select list in my edit form and i want to see the right ethinicty selected for the person i am editing

<%= 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 %>    

Person.rb

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

I want the right value for the ethnicity selected on edit. How do i do that?
With what i did i don't have a value for ethnicity when i am on the edit page

mamesaye
  • 2,033
  • 2
  • 32
  • 49

1 Answers1

1

Set a value_method for the select list as shown below:

<%= f.input :ethnicity,
                collection: Person.select('distinct ethnicity'),
                :label_method =>  :ethnicity,
                :value_method =>  :ethnicity,    
                :input_html => {:class => 'chosen-select'} %> 
Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108