我使用Rails 3.1和Ruby 1.9.2以及Active Admin来构建CMS。这是我的Place和Image模型:
class Place < ActiveRecord::Base
has_one :image
accepts_nested_attributes_for :image
end
class Image < ActiveRecord::Base
belongs_to :place
end
以下是我在Places控制器中的“新”操作中呈现的Formtastic表单:
<%= semantic_form_for [:admin, @place] do |p| %>
<%= p.inputs "Details" do %>
<%= p.input :name %>
<%= p.input :description %>
<%= p.input :phone %>
<%= p.input :address %>
<%= p.input :image %>
<% end %>
<%= p.buttons %>
<% end %>
当我在浏览器中加载表单时,我看到以下错误:
undefined method `place_id' for #<Place:0xb801744>
以下是踢球者:在我的Place模型中,如果我将has_one :image
更改为has_many :images
而将accepts_nested_attributes_for :image
更改为accepts_nested_attributes_for :images
,并在我的表单中更改p.input :image
到p.input :images
,然后错误消失,Formtastic正确呈现包含所有可用图像对象的多选输入元素。那么,当我使用has_one
关联而不是看到select输入元素时,为什么会出现此错误?
答案 0 :(得分:2)
根据https://github.com/gregbell/active_admin/issues/575,这是formtastic和主动管理员之间的错误 - 我建议你在github上关注这个问题,并向他们解释你的情况,如果有多个社区成员报告,它可能会提示修复问题。