나는 새로운 오전를 사용하여 형태를 구축 할 formtastic, ActiveAdmin을, STI 및 다형성 협회의 조합을 사용하여 폼로드 오류편집 레일에 Formtastic, STI, 다형성 및 ActiveAdmin을
II가있는 중첩 된 양식을 만들 수있는 경우 문제가 없지만 STI를 소개하고 build_address 대신 build_origin_address를 시도하면 편집보기를로드 할 때 아래 오류가 발생합니다.
NameError in Admin/leads # edit 표시 중 .../app /views/admin/leads/_form.erb 여기서 3 번 줄은 : 초기화되지 않은 상수 Lead :: OriginAddress
,210모델 : 편집보기에서
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