使用Formtastic,STI,Polymorphic&amp ;;编辑表单加载错误ActiveAdmin

时间:2012-01-11 01:28:43

标签: ruby-on-rails formtastic activeadmin

我是rails的新手,并使用formtastic,activeadmin,sti和多态关联的组合来构建表单

当我可以使用地址parent创建一个没有问题的嵌套表单时,但是当我引入STI并尝试build_origin_address而不是build_address时,就是当我在加载编辑视图时收到以下错误

Admin / lead#edit中的NameError 显示... / 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 %>

1 个答案:

答案 0 :(得分:0)

我认为你必须在表单之前定义@lead。