我得到一个
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">