Azr*_*ren 4 ruby-on-rails simple-form
我正在尝试使用simple_form为'Member'创建一个表单,并且在显示组织时无法显示组织,而不是id或organization_name.我在这里错过了什么吗?我该怎么办呢?
**组织: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 %>
Run Code Online (Sandbox Code Playgroud)
谢谢.
干杯,阿兹伦
看起来Organization模型没有任何这些字段:[ :to_label, :name, :title, :to_s ]因此SimpleForm无法检测默认标签和值集合方法.我认为你应该手动传递它.
小智 5
将to_label函数添加到您的组织类,如下所示
class Organization < ActiveRecord::Base
has_many :members
attr_accessible :organization_name
def to_label
"#{organization_name}"
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8057 次 |
| 最近记录: |