Rails选择标签

时间:2012-08-13 14:07:56

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

我正在尝试使用select标签显示性别模型。这是我的模特

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 个答案:

答案 0 :(得分:1)

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

  

collection_select(:customer,:gender_id,Gen​​der.all,:id,   :描述)