【问题标题】:"stack level too deep" error in show#controller for nested forms嵌套表单的 show#controller 中的“堆栈级别太深”错误
【发布时间】:2012-12-11 16:19:07
【问题描述】:

我得到一个

Admin::ChecklistsController#show 中的 SystemStackError

堆栈级别太深

控制器动作:

# 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 日开始为 192.168.4.191 获取“/admin/checklists/4” 10:12:41 +0100 管理员处理::ChecklistsController#show as HTML 参数:{"id"=>"4"} Admin::Checklist Load (0.2ms) SELECT “admin_checklists”。*来自“admin_checkli
sts" WHERE "admin_checklists"."id" = ? LIMIT 1 [["id", "4"]] 缓存 (0.0ms) SELECT "admin_checklists".* FROM "admin_checklists" WHERE “阿米
n_checklists"."id" = ? LIMIT 1 [["id", "4"]] 已完成 500 内部 240 毫秒内的服务器错误

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/middlew 在救援/布局中是/templates/rescues/diagnostics.erb (10.7ms)

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

编辑2:

irb(main):001:0> Admin::Checklist.find('4') Admin::Checklist 加载 (0.2ms) SELECT "admin_checklists".* FROM "admin_checkli
sts" WHERE "admin_checklists"."id" = ? LIMIT 1 [["id", "4"]] => # BrummliBrummliBrummliBrummliBrummliBrummliBr...”,可用:假, created_at:“20 12-12-11 13:43:23”, 更新时间:“2012-12-11 13:43:23">

【问题讨论】:

  • 摆脱了`show.html.erb`Docs
  • 这不是问题,我知道错了,错误是由 find 动作触发的。我编辑了顶帖。
  • 试图寻找类似的东西,你在这个问题上使用的是什么版本的 Rails?

标签: ruby-on-rails-3 activerecord


【解决方案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 %>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    相关资源
    最近更新 更多