Hi everyone,
I'm not sure exactly what's happening here.  I had the following work
perfectly in 0.13.1:
class ProductCategory < ActiveRecord::Base
  acts_as_tree :order => 'name'
end
class Admin::ProductCatalog::ProductsController < Admin::SecureController
  before_filter :setup_nav, :only => [:public_index, :public_view]
  def public_index
    @page_title = "Browsing #{@root.name}"
  end
protected
  def setup_nav
    @toplevel = Configuration.get(:public_root_category)
    @root = session[:root] || @toplevel
    @parents = [@root]
    while @parents.first != @toplevel && @parents.first.parent
      @parents.unshift @parents.first.parent
    end
  end
end
@toplevel is an instance of ProductCategory.  If I restart WEBrick,
#public_index renders perfectly.  If I refresh, I get an undefined
method exception when #parent is called.
I changed setup_nav like this for debugging purposes:
def setup_nav
  @toplevel = Configuration.get(:public_root_category)
  @root = session[:root] || @toplevel
  render :inline => %q(<%= debug(@root)
%><br><br><%@root.has_parent? %><br><%= RAILS_ENV
%>)
  return false
end
On the first load, I get this:
<pre class='debug_dump'>--- !ruby/object:ProductCategory
attributes:
  name: All Categories
  id: "128"
  picture_id:
  parent_id: </pre><br><br>false<br>development
On the second and subsequent reloads, I instead get the following exception:
 NoMethodError in Admin/product_catalog/products#public_index
undefined method `has_parent?' for #<ProductCategory:0x36ef4e0>
Application Trace | Framework Trace | Full Trace
./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1390:in
`method_missing'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:72:in
`send'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:72:in
`method_missing'
compiled-template:1
./script/../config/../app/controllers/admin/product_catalog/products_controller.rb:230:in
`setup_nav'
[snip -- complete stack trace at end]
There must be something I'm doing wrong, but for the life of me, I
can't see what that is...  This application is running under a
Productized version, if that changes anything.  I have confirmed that
I'm running in dev mode (as seen above).
NOTE: If I use the new #ancestors method in ActsAsTree, I get the same
kind of behavior - works on first call, fails on subsequent ones.
Thanks for any help in debugging this...
Bye !
François
Complete Stack Trace
 NoMethodError in Admin/product_catalog/products#public_index
undefined method `has_parent?' for #<ProductCategory:0x36ef4e0>
Application Trace | Framework Trace | Full Trace
./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1390:in
`method_missing'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:72:in
`send'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:72:in
`method_missing'
compiled-template:1
./script/../config/../app/controllers/admin/product_catalog/products_controller.rb:230:in
`setup_nav'
./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1390:in
`method_missing'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:72:in
`send'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:72:in
`method_missing'
./script/../config/../vendor/rails/actionpack/lib/action_view/base.rb:269:in
`send'
./script/../config/../vendor/rails/actionpack/lib/action_view/base.rb:269:in
`compile_and_render_template'
./script/../config/../vendor/rails/actionpack/lib/action_view/base.rb:245:in
`render_template'
./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:645:in
`render_template'
./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:596:in
`render_with_no_layout'
./script/../config/../vendor/rails/actionpack/lib/action_controller/layout.rb:225:in
`render_without_benchmark'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:in
`render'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:in
`measure'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:in
`render'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:317:in
`send'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:317:in
`call_filters'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:313:in
`each'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:313:in
`call_filters'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:302:in
`before_action'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:294:in
`perform_action_without_benchmark'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
`measure'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
./script/../config/../vendor/rails/actionpack/lib/action_controller/rescue.rb:82:in
`perform_action'
./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:364:in
`send'
./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:364:in
`process_without_session_management_support'
./script/../config/../vendor/rails/actionpack/lib/action_controller/session_management.rb:116:in
`process'
./script/../config/../vendor/rails/railties/lib/dispatcher.rb:36:in
`dispatch'
./script/../config/../vendor/rails/railties/lib/webrick_server.rb:117:in
`handle_dispatch'
./script/../config/../vendor/rails/railties/lib/webrick_server.rb:83:in
`service'
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
C:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread'
C:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'
C:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each'
C:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'
./script/../config/../vendor/rails/railties/lib/webrick_server.rb:69:in
`dispatch'
./script/../config/../vendor/rails/railties/lib/commands/server.rb:59
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
script/server:3
./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1390:in
`method_missing'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:72:in
`send'
./script/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:72:in
`method_missing'
compiled-template:1
./script/../config/../vendor/rails/actionpack/lib/action_view/base.rb:269:in
`send'
./script/../config/../vendor/rails/actionpack/lib/action_view/base.rb:269:in
`compile_and_render_template'
./script/../config/../vendor/rails/actionpack/lib/action_view/base.rb:245:in
`render_template'
./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:645:in
`render_template'
./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:596:in
`render_with_no_layout'
./script/../config/../vendor/rails/actionpack/lib/action_controller/layout.rb:225:in
`render_without_benchmark'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:in
`render'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:in
`measure'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:in
`render'
./script/../config/../app/controllers/admin/product_catalog/products_controller.rb:230:in
`setup_nav'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:317:in
`send'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:317:in
`call_filters'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:313:in
`each'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:313:in
`call_filters'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:302:in
`before_action'
./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:294:in
`perform_action_without_benchmark'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
`measure'
./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
./script/../config/../vendor/rails/actionpack/lib/action_controller/rescue.rb:82:in
`perform_action'
./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:364:in
`send'
./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:364:in
`process_without_session_management_support'
./script/../config/../vendor/rails/actionpack/lib/action_controller/session_management.rb:116:in
`process'
./script/../config/../vendor/rails/railties/lib/dispatcher.rb:36:in
`dispatch'
./script/../config/../vendor/rails/railties/lib/webrick_server.rb:117:in
`handle_dispatch'
./script/../config/../vendor/rails/railties/lib/webrick_server.rb:83:in
`service'
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
C:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread'
C:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'
C:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each'
C:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'
./script/../config/../vendor/rails/railties/lib/webrick_server.rb:69:in
`dispatch'
./script/../config/../vendor/rails/railties/lib/commands/server.rb:59
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
script/server:3
Request
Parameters: {"category_path"=>[]}
Show session dump
{:root=>#<ProductCategory:0x36ef4e0 @parent=nil,
@attributes={"name"=>"All Categories",
"id"=>"128", "picture_id"=>nil,
"parent_id"=>nil}>, "flash"=>{}}
Response
Headers: {"cookie"=>[],
"Cache-Control"=>"no-cache"}
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails