我新的軌道,並使用formtastic,activeadmin,STI和多態關聯的組合來建立一個form表單加載錯誤編輯使用Formtastic,STI,多晶型ActiveAdmin
當II可以創建一個嵌套的表格地址父沒有問題,但是當我引入STI並嘗試build_origin_address而不是build_address,即當我在加載編輯視圖時出現下面的錯誤
NameError在Admin/leads#edit 正在顯示.../app /views/admin/leads/_form.erb其中第3行產生: 未初始化的常量Lead :: OriginAddress
種模式:在編輯視圖
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
belongs_to :lead
validates :line1, :presence => true, :length => {:minimum => 2}
attr_accessible :line1, :line2, :city, :state, :zip, :country
end
class OriginAddress < Address
end
class DestinationAddress < Address
end
class Lead < ActiveRecord::Base
has_one :origin_address, :dependent => :destroy, :as => :addressable
accepts_nested_attributes_for :origin_address, :allow_destroy => true
end
部分使用:
<%= semantic_form_for [:admin, @lead] do |f| %>
<% @lead.build_origin_address unless @lead.origin_address %>
<%= f.inputs :name => "Lead Info" do %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<% end %>
<%= f.semantic_fields_for :origin_address do |origin| %>
<%= origin.inputs :name => "Origin Address" do %>
<%= origin.input :line1 %>
....
<% end %>
<% end %>
<%= f.buttons do %>
<%= f.commit_button %>
<% end %>
<% end %>
上面的代碼是否顯示整個Lead類定義?該錯誤消息表明它正在尋找OriginAddress,將其命名爲Lead類中的某處,但無法找到它。你在引用Lead類中的OriginAddress類嗎?如果是這樣,你可以通過在const名稱前面添加'::'來解決這個問題。即':: OriginAddress' – OutlawAndy 2013-06-30 17:31:25