2

我得到一个

SystemStackError in Admin::ChecklistsController#show

堆栈级别太深

控制器动作:

# GET /admin/checklists/1
# GET /admin/checklists/1.json
def show
  @admin_checklist = Admin::Checklist.find(params[:id])

  respond_to do |format|
    format.html #show.html.erb
    format.json { render json: @admin_checklist }
  end
end

和模型

class Admin::Checklist < ActiveRecord::Base
  attr_accessible :description, :name, :usable, :categories_attributes
  has_many :categories, :dependent => :destroy
  validates_presence_of :name,:description

  accepts_nested_attributes_for :categories, :allow_destroy => true

end

class Admin::Category < ActiveRecord::Base
  attr_accessible :export_head, :export_position, :export_text, :frontend_head, :frontend_position, :frontend_text
  belongs_to :checklist
  validates_presence_of :frontend_head, :frontend_text

end

我已经玩了一下attributes_accessible。如果我将 :categories_attributes 替换为 :categories

然后我松开了无限循环错误,但正如预期的那样,我不能再批量分配任何类别属性

任何人都知道如何解决这两个错误。

编辑:

在 2012-12-12 10:12:41 +0100 开始 GET "/admin/checklists/4" for 192.168.4.191 +0100 由 Admin::ChecklistsController#show 作为 HTML 参数处理:{"id"=>"4"} Admin ::Checklist Load (0.2ms) SELECT "admin_checklists".* FROM "admin_checklists
" WHERE "admin_checklists"."id" = ? LIMIT 1 [["id", "4"]] CACHE (0.0ms) SELECT "admin_checklists".* FROM "admin_checklists" WHERE "
admin_checklists"."id" = ? LIMIT 1 [["id", "4"]] 在 240 毫秒内完成 500 内部服务器错误

SystemStackError(堆栈级别太深):actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:70

渲染 /var/lib/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middlew are/templates/rescues/_trace.erb (1.5ms) 渲染 /var/lib/gems/1.9.1/ gems/actionpack-3.2.9/lib/action_dispatch/middlew are/templates/rescues/_request_and_response.erb (1.3ms) 渲染/var/lib/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/救援/布局中的中间件是/templates/rescues/diagnostics.erb (10.7ms)

对于每个 Page 请求,我得到这个 SQL-Staement 大约 100 次。这似乎是活动记录中的一些错误或我对嵌套模型的活动记录的误用.....

编辑2:

irb(main):001:0> Admin::Checklist.find('4') Admin::Checklist Load (0.2ms) SELECT "admin_checklists".* FROM "admin_checklists
" WHERE "admin_checklists"."id" = ? LIMIT 1 [["id", "4"]] => # BrummliBrummliBrummliBrummliBrummliBrummliBr...",可用:false,created_at:"20 12-12-11 13:43:23",updated_at:"2012-12-11 13:43:23">

4

1 回答 1

1

有趣的事实是它现在可以工作了,我不太确定是什么真正修复了它,因为我什么也没做。我刚休息完回来。在控制台上找到了。再次在模板中检查它,我收到一条属于格式错误的循环的不同错误消息,因为我再次删除了它,我通过再次粘贴删除的部分来修复它。

<p id="notice"><%= notice %></p>

<p>
  <b>Name:</b>
  <%= @admin_checklist.name %>
</p>

<p>
  <b>Description:</b>
  <%= @admin_checklist.description %>
</p>

<p>
  <b>Usable:</b>
  <%= @admin_checklist.usable %>
</p>

<p>
    <ul>
        <% @admin_checklist.categories.each do |category|%>
            <li>
                <h3><%= category.frontend_head %></h3>
                <p><%= category.frontend_text %></p>
            </li>
        <% end %>
    </ul>
</p>


<%= link_to 'Edit', edit_admin_checklist_path(@admin_checklist) %> |
<%= link_to 'Back', admin_checklists_path %>

很抱歉,我无法回答为什么会发生这种情况。

于 2012-12-12T12:52:40.650 回答