【发布时间】:2012-04-09 03:43:21
【问题描述】:
我正在尝试使用 simple_form 为“成员”创建一个表单,但在显示关联时遇到了问题,它显示的组织如下所示,而不是 id 或组织名称。我在这里错过了什么吗?我该怎么办?
**组织:0x0000000485cf88
组织:0x0000000485c948
组织:0x0000000485c358**
class Organization < ActiveRecord::Base
has_many :members
attr_accessible :organization_name
end
class Member < ActiveRecord::Base
belongs_to :organization
attr_accessible :active, :email, :first_name, :last_name, :role
end
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :role %>
<%= f.input :email %>
<%= f.input :active %>
<%= f.association :organization %>
<%= f.button :submit %>
谢谢。
干杯, 阿兹伦
【问题讨论】:
-
你能把
members_controller的new动作和整个表格展示出来吗? -
看起来组织模型没有以下任何字段:
[ :to_label, :name, :title, :to_s ]所以SimpleForm无法检测到用于收集的默认标签和值方法。我认为你应该手动传递它。 -
使用 :to_label 方法解决。谢谢。
-
顺便记录一下,我在成员迁移中使用了组织:引用,如果我只使用组织 ID:整数,这将是我使用 f.association 所期望的:组织。无论如何感谢你们的帮助。欣赏。