0

我正在尝试显示带有选择标签的性别模型。这是我的模型

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" %>
4

1 回答 1

1

我希望您尝试在客户表单中添加一个性别复选框。如果是这样,它应该是

collection_select(:customer, :gender_id, Gender.all, :id, :description)

于 2012-08-13T14:15:40.943 回答