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 %>

presents_fields:

<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 に答える