What was the intended way to include files that extend AR models? For example, I have a class called UserAction < ActiveRecord::Base end I would like to include test.rb file in environment.rb that subclasses UserAction like so : CommentUserAction < UserAction end However, if I do this with cache_classes = false, then things will get screwed up because UserAction will get unloaded between requests. I tried to use "require_dependency ''test.rb''", but I was running into problems with that as well. In the past we''d use something like "include Reloadable" but thats deprecated now. Any help would be greatly appreciated. -- 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 -~----------~----~----~----~------~----~------~--~---
Aryk Grosz wrote:> What was the intended way to include files that extend AR models? > > For example, I have a class called > > UserAction < ActiveRecord::Base > end > > I would like to include test.rb file in environment.rb that subclasses > UserAction like so : > > CommentUserAction < UserAction > end > > However, if I do this with cache_classes = false, then things will get > screwed up because UserAction will get unloaded between requests. > > I tried to use "require_dependency ''test.rb''", but I was running into > problems with that as well. > > In the past we''d use something like "include Reloadable" but thats > deprecated now. > > Any help would be greatly appreciated.Can you put test.rb in the lib or models directories as comment_user_action.rb? If not, below your "require test.rb" in environment.rb add "CommentUserAction". This should trigger loading of both classes. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I can''t put comment_user_action in lib or models directories because in my case I have like 15 of these classes that extend UserAction, and making 15 files is a pain in the butt. As for putting "CommentUserAction" under the require line in the environment.rb. Im not sure how helpful this would be because, the code from environment.rb only gets run once. So I think I''d still run into the same problem once UserAction gets unloaded between requests. I solved it by putting require_dependency "test.rb" in application.rb. This works since application.rb gets reloaded between requests, but I''d hate to be adding model requires in the application.rb file. Any thoughts? Aryk Mark Reginald James wrote:> Aryk Grosz wrote: >> CommentUserAction < UserAction >> >> Any help would be greatly appreciated. > > Can you put test.rb in the lib or models directories as > comment_user_action.rb? > > If not, below your "require test.rb" in environment.rb > add "CommentUserAction". This should trigger loading of > both classes. > > -- > We develop, watch us RoR, in numbers too big to ignore.-- 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 -~----------~----~----~----~------~----~------~--~---