2012-08-13 246 views
0

我想用選擇標籤顯示性別模型。在這裏我的模型Rails選擇標籤

Customer  Gender 
ID    Id 
First   Customer_id 
Last   description 
Email 
Password 

Customer 
    has_one :gender 
Gender 
    belongs_to :customer 

這裏我選擇標記的ATM

<%= collection_select(:gender, :id, Gender.all, :id, :description) %> 

但它顯示我下面的錯誤,而不是

NoMethodError in Customers#edit 

Showing /home/jean/rail/map/app/views/customers/_general.html.erb where line #23 raised: 

undefined method `id' for []:Array 
Extracted source (around line #23): 

20:  
21:  <%= #collection_select(:gender, :description, @genders, :id, :description) 
22:  %> 
23:  <%= collection_select(:gender, :id, Gender.all, :id, :description) %> 
24: 
25:  <div class="customer_edit_name"> 
26:    <%= f.label "Birthday" %> 

回答

1

我希望你嘗試添加性別的複選框中客戶表單。如果是的話,應該是作爲

collection_select(:客戶:gender_id,Gen​​der.all,:ID, :描述)