问题描述
我正在尝试使用 simple_form 为会员"创建一个表单,但在显示关联时遇到问题,其中显示的组织如下所示,而不是 id 或组织名称.我在这里错过了什么吗?我应该怎么做?
I'm trying to create a form for 'Member' using simple_form and having trouble displaying an association where it display the organization as below instead of the id, or organization_name. Am I missing something here? How should I go about this?
**组织:0x0000000485cf88
**Organization:0x0000000485cf88
组织:0x0000000485c948
Organization:0x0000000485c948
组织:0x0000000485c358**
Organization: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 %>
谢谢.
干杯,阿兹伦
推荐答案
看起来像 Organization
模型没有以下任何字段:[ :to_label, :name, :title,:to_s ]
所以 SimpleForm
无法检测集合的默认标签和值方法.我认为你应该手动传递它.
looks like Organization
model doesn't have any of these fields: [ :to_label, :name, :title, :to_s ]
so SimpleForm
can't detect a default label and value methods for collection. I think you should pass it manually.
这篇关于Rails simple_form 关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!