1

在“编辑”或“显示”时出现:

ActiveRecord::SubclassNotFound in Registries#edit

“单表继承机制未能定位子类:‘Plane’。引发此错误是因为‘type’列保留用于存储类以防继承。如果您不打算重命名此列,请重命名它用于存储继承类或覆盖 Present.inheritance_column 以使用另一列存储该信息。”

25:   </div>
26:   
27:   <div class="field1">
28:   <%= f.fields_for :presents do |builder| %>
29:   <%= render 'present_fields', f: builder %>
30:   <% end %>
31:   </div>

这是注册表:

<%= nested_form_for(@registry) do |f| %>
<% if @registry.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@registry.errors.count, "error") %> prohibited this registry from    
being saved:</h2>

  <ul>
  <% @registry.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
</div>
<% end %>


<%= f.label :due_date %><br />
<%= f.date_select :due_date, :rows => 5 %>


<%= f.label :theme %><br />
<%= f.text_field :theme, :class => 'field2' %>

<div class="field1">
<%= f.label :gender %><br />
<%= f.text_field :gender %>
</div>

<div class="field1">
<%= f.fields_for :presents do |builder| %>
<%= render 'present_fields', f: builder %>
<% end %>
</div>

<%= link_to_add_fields "Add Presents", f, :presents %>

<div class="actions">
<%= f.submit %>
</div>
<% end %>

礼物字段:

<div class="field1">
<table>
<tr> 
<td> <%= f.label :type, "Present Type" %> </td>
<td> <%= f.text_field :type, :class => 'field2' %> </td>
<td> <%= f.label :Quantity, "Quantity" %> </td>
<td> <%= f.number_field :quantity, :class => 'field3' %> </td>
<td> <%= f.label :color, "Color" %> </td>
<td> <%= f.text_field :color, :class => 'field2' %> </td>
<td> <%= f.label :brand, "Brand" %> </td>
<td> <%= f.text_field :brand, :class => 'field2' %> </td>
<td> <%= f.link_to_remove "Remove this present" %></td>
</tr>
</table>
</div>
4

1 回答 1

3

重命名或覆盖,因为错误说通过类似的方式覆盖

set_inheritance_column "not_sti"

来源: http: //my.safaribooksonline.com/book/web-development/ruby/9780132480345/advanced-active-record/ch09lev1sec5

于 2012-06-12T16:30:59.267 回答