I just upgraded from 1.2.3 to 2.1.0 and now I''m seeing a model reloading problem in development. If I set config.cache_classes = true, the problem goes away (which obviously isn''t a very good workaround in development). I get errors like this for nested associations called in a controller (ie, :include => {:team_players => :person}): Association named ''person'' was not found; perhaps you misspelled it? I load the page the first time and it works fine. Subsequent page loads fails. I''ve also found that I can''t call on an association in a View that wasn''t preloaded in the controller. So if I do this in the controller: @teams = Ball::Team.find(:all, :conditions => "active = 1", :include => :team_players) it will not let me do this: <% for t in @teams %> Team: <%= t.name %><br> <% for tp in t.team_players %> Player name: <%= tp.person.full_name %> <!-- it croaks here on the person association -> <% end %> <% end %> The only real complexity with my configuration is that my models are in subdirectories (so Ball::Team is in models/ball/team.rb). I set this in my environments.rb file when I was running 1.2.3: config.load_paths += Dir[RAILS_ROOT + ''/app/models/*/''] But now with rails 2.1.0, it isn''t working. Again, setting config.cache_classes to true makes the problem go away, but I''d rather downgrade to 1.2.6 than restart my mongrels every time i make a change. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Jul 2008, at 13:46, Robbie Allen wrote:> > I just upgraded from 1.2.3 to 2.1.0 and now I''m seeing a model > reloading > problem in development. If I set config.cache_classes = true, the > problem goes away (which obviously isn''t a very good workaround in > development).Do you require models explicitly (this can confuse the dependencies stuff). Do you use any plugins that hang on to model classes (or instances of them) ? Fred> > > I get errors like this for nested associations called in a controller > (ie, :include => {:team_players => :person}): > > Association named ''person'' was not found; perhaps you misspelled > it? > > I load the page the first time and it works fine. Subsequent page > loads > fails. > > I''ve also found that I can''t call on an association in a View that > wasn''t preloaded in the controller. > > So if I do this in the controller: > > @teams = Ball::Team.find(:all, :conditions => "active = 1", :include > => > :team_players) > > it will not let me do this: > > <% for t in @teams %> > Team: <%= t.name %><br> > <% for tp in t.team_players %> > Player name: <%= tp.person.full_name %> <!-- it croaks here on > the > person association -> > <% end %> > <% end %> > > The only real complexity with my configuration is that my models are > in > subdirectories (so Ball::Team is in models/ball/team.rb). I set > this in > my environments.rb file when I was running 1.2.3: > > config.load_paths += Dir[RAILS_ROOT + ''/app/models/*/''] > > But now with rails 2.1.0, it isn''t working. Again, setting > config.cache_classes to true makes the problem go away, but I''d rather > downgrade to 1.2.6 than restart my mongrels every time i make a > change. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Robbie! On Wed, Jul 2, 2008 at 7:46 AM, Robbie Allen < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I just upgraded from 1.2.3 to 2.1.0 and now I''m seeing a model reloading > problem in development. If I set config.cache_classes = true, the > problem goes away (which obviously isn''t a very good workaround in > development). > > I get errors like this for nested associations called in a controller > (ie, :include => {:team_players => :person}): > > Association named ''person'' was not found; perhaps you misspelled > it? > > I load the page the first time and it works fine. Subsequent page loads > fails. > > I''ve also found that I can''t call on an association in a View that > wasn''t preloaded in the controller. > > So if I do this in the controller: > > @teams = Ball::Team.find(:all, :conditions => "active = 1", :include => > :team_players) > > it will not let me do this: > > <% for t in @teams %> > Team: <%= t.name %><br> > <% for tp in t.team_players %> > Player name: <%= tp.person.full_name %> <!-- it croaks here on the > person association -> > <% end %> > <% end %> > > The only real complexity with my configuration is that my models are in > subdirectories (so Ball::Team is in models/ball/team.rb). I set this in > my environments.rb file when I was running 1.2.3: > > config.load_paths += Dir[RAILS_ROOT + ''/app/models/*/''] > > But now with rails 2.1.0, it isn''t working. Again, setting > config.cache_classes to true makes the problem go away, but I''d rather > downgrade to 1.2.6 than restart my mongrels every time i make a change. > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Robbie: (last message got cut off somehow.) Can you try to upgrade from 1.2.3 to 1.2.6 and run your tests? 1.2.6 posts lots of deprecation warnings and is meant to be a transitional version. You might find something useful there. I suspect that the load-paths thing you''re doing is causing the problem. The first thing I''d do is explicitly add each model subfolder instead of * and see if that works. If it does, then perhaps this patch addresses it. http://github.com/rails/rails/commit/cce30f71246dbc5433153156afa4f952553ad13d I don''t typically do this in my models folder - I''m pretty content with a flat folder structure, even with +100 models. On Wed, Jul 2, 2008 at 8:17 AM, Brian Hogan <bphogan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Robbie! > > > On Wed, Jul 2, 2008 at 7:46 AM, Robbie Allen < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> I just upgraded from 1.2.3 to 2.1.0 and now I''m seeing a model reloading >> problem in development. If I set config.cache_classes = true, the >> problem goes away (which obviously isn''t a very good workaround in >> development). >> >> I get errors like this for nested associations called in a controller >> (ie, :include => {:team_players => :person}): >> >> Association named ''person'' was not found; perhaps you misspelled >> it? >> >> I load the page the first time and it works fine. Subsequent page loads >> fails. >> >> I''ve also found that I can''t call on an association in a View that >> wasn''t preloaded in the controller. >> >> So if I do this in the controller: >> >> @teams = Ball::Team.find(:all, :conditions => "active = 1", :include => >> :team_players) >> >> it will not let me do this: >> >> <% for t in @teams %> >> Team: <%= t.name %><br> >> <% for tp in t.team_players %> >> Player name: <%= tp.person.full_name %> <!-- it croaks here on the >> person association -> >> <% end %> >> <% end %> >> >> The only real complexity with my configuration is that my models are in >> subdirectories (so Ball::Team is in models/ball/team.rb). I set this in >> my environments.rb file when I was running 1.2.3: >> >> config.load_paths += Dir[RAILS_ROOT + ''/app/models/*/''] >> >> But now with rails 2.1.0, it isn''t working. Again, setting >> config.cache_classes to true makes the problem go away, but I''d rather >> downgrade to 1.2.6 than restart my mongrels every time i make a change. >> -- >> Posted via http://www.ruby-forum.com/. >> >> >> >> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Do you require models explicitly (this can confuse the dependencies > stuff).No.> Do you use any plugins that hang on to model classes (or > instances of them) ? > > FredI''m using several external plugins. How would I find out? Did the behavior for how this is handled change between 1.x and 2.x? Regards, Robbie http://statsheet.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Jul 2008, at 14:25, Robbie Allen wrote:> >> Do you require models explicitly (this can confuse the dependencies >> stuff). > > No. > >> Do you use any plugins that hang on to model classes (or >> instances of them) ? >> >> Fred > > I''m using several external plugins. How would I find out? Did the > behavior for how this is handled change between 1.x and 2.x? >Plugins used to be reloaded with each request by default, but they aren''t anymore. I can''t remember when this change happened to be honest. I have a feeling it was in 1.2 but it could have been 2.0 I''ve got some info on making plugins be reloaded on each request here http://www.spacevatican.org/2008/5/28/reload-me-reload-me-not , you could try that out to exclude it as a source of problems (alternatively examine Dependencies.load_once_paths in your 1.2 app: if it looks the same there as in 2.0 then that''s probably not the problem) Fred> Regards, > Robbie > http://statsheet.com > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brian Hogan wrote:> Hi Robbie:Hi Brian. I hope you are doing well.> (last message got cut off somehow.) > > Can you try to upgrade from 1.2.3 to 1.2.6 and run your tests? 1.2.6 > posts lots of deprecation warnings and is meant to be a transitional version. > You might find something useful there.Just tried that and no errors. It worked fine, just like 1.2.3.> I suspect that the load-paths thing you''re doing is causing the problem.That is the suggested solution if you have models in subdirectories.> The first thing I''d do is explicitly add each model subfolder instead of * > and see if that works. If it does, then perhaps this patch addresses it.Tried it, no difference.> http://github.com/rails/rails/commit/cce30f71246dbc5433153156afa4f952553ad13dI applied it, but it started complaining. It looks like other patches are required before applying that patch.> I don''t typically do this in my models folder - I''m pretty content with > a flat folder structure, even with +100 models.I have 232 models and counting. It is a rather large app that is naturally hierarchical and using subdirectories made logical sense. Unfortunately Rails doesn''t handle it very well. Any other suggestions? :-) Regards, Robbie http://statsheet.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Jul 2008, at 15:30, Robbie Allen wrote:> . > >> I don''t typically do this in my models folder - I''m pretty content >> with >> a flat folder structure, even with +100 models. > > I have 232 models and counting. It is a rather large app that is > naturally hierarchical and using subdirectories made logical sense. > Unfortunately Rails doesn''t handle it very well. >Probably not relevant to the question at hand, but you can stick your models in separate folders without namespacing them: http://blog.hasmanythrough.com/2008/5/6/a-simple-alternative-to-namespaced-models Fred> Any other suggestions? :-) > > Regards, > Robbie > http://statsheet.com > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Here is a simple example of what I''m talking about. My first example uses Rails 1.2.6: script/console Loading development environment.>> conf.return_format = "" >> cs = Ball::CoachSeason.find(:first) >> puts cs.coach.full_nameDavid Aaron>> reload!Reloading...>> cs = Ball::CoachSeason.find(:first) >> puts cs.coach.full_nameDavid Aaron>>Second example uses 2.1.0: script/console Loading development environment (Rails 2.1.0)>> conf.return_format = "" >> cs = Ball::CoachSeason.find(:first) >> puts cs.coach.full_nameDavid Aaron>> reload!Reloading...>> cs = Ball::CoachSeason.find(:first) >> puts cs.coach.full_nameNoMethodError: undefined method `full_name'' for #<Ball::Coach:0x2ab4ce75fbe0> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/attribute_methods.rb:256:in `method_missing'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:177:in `send'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:177:in `method_missing'' from (irb):7 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Jul 2008, at 15:43, Robbie Allen wrote:> > Here is a simple example of what I''m talking about. >Anything interesting in the models ? Have you been able to construct a small app from scratch that exhibits the problem ? Fred> My first example uses Rails 1.2.6: > > script/console > Loading development environment. >>> conf.return_format = "" >>> cs = Ball::CoachSeason.find(:first) >>> puts cs.coach.full_name > David Aaron >>> reload! > Reloading... >>> cs = Ball::CoachSeason.find(:first) >>> puts cs.coach.full_name > David Aaron >>> > > > Second example uses 2.1.0: > > script/console > Loading development environment (Rails 2.1.0) >>> conf.return_format = "" >>> cs = Ball::CoachSeason.find(:first) >>> puts cs.coach.full_name > David Aaron >>> reload! > Reloading... >>> cs = Ball::CoachSeason.find(:first) >>> puts cs.coach.full_name > NoMethodError: undefined method `full_name'' for > #<Ball::Coach:0x2ab4ce75fbe0> > from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ > attribute_methods.rb:256:in > `method_missing'' > from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ > associations/association_proxy.rb:177:in > `send'' > from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ > associations/association_proxy.rb:177:in > `method_missing'' > from (irb):7 > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ahhh! I didn''t see the namespacing that you''re doing. I recommend Fred''s suggestion. Namespacing of models seems to get broken a lot. I''ve done Rails for over 3 years now and it''s been broken at least twice before (that I remember). That doesn''t excuse it breaking of course. Here''s an idea... can you run on edge and see it that fixes it? On Wed, Jul 2, 2008 at 9:55 AM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 2 Jul 2008, at 15:43, Robbie Allen wrote: > > > > > Here is a simple example of what I''m talking about. > > > Anything interesting in the models ? Have you been able to construct a > small app from scratch that exhibits the problem ? > > Fred > > > My first example uses Rails 1.2.6: > > > > script/console > > Loading development environment. > >>> conf.return_format = "" > >>> cs = Ball::CoachSeason.find(:first) > >>> puts cs.coach.full_name > > David Aaron > >>> reload! > > Reloading... > >>> cs = Ball::CoachSeason.find(:first) > >>> puts cs.coach.full_name > > David Aaron > >>> > > > > > > Second example uses 2.1.0: > > > > script/console > > Loading development environment (Rails 2.1.0) > >>> conf.return_format = "" > >>> cs = Ball::CoachSeason.find(:first) > >>> puts cs.coach.full_name > > David Aaron > >>> reload! > > Reloading... > >>> cs = Ball::CoachSeason.find(:first) > >>> puts cs.coach.full_name > > NoMethodError: undefined method `full_name'' for > > #<Ball::Coach:0x2ab4ce75fbe0> > > from > > /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ > > attribute_methods.rb:256:in > > `method_missing'' > > from > > /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ > > associations/association_proxy.rb:177:in > > `send'' > > from > > /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ > > associations/association_proxy.rb:177:in > > `method_missing'' > > from (irb):7 > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks to Fred and Brian''s suggestions, I was able to track this down. For some unknown reason I had put "include Ball" (using my previous example) in lib/search.rb. After I removed it, the reload problem went away. Strange, but whatever ;-) I''m just glad it is fixed. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---