Hello. I''m wondering how to add methods to a model (stored in /app/models) from a ruby file located in /lib/my-extension for instance. How is it possible? Are the models of an app stored in a specific ruby module? Thanks. aurels --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Aurels wrote:> I''m wondering how to add methods to a model (stored in /app/models) > from a ruby file located in /lib/my-extension for instance. How is it > possible? Are the models of an app stored in a specific ruby module?Classes often must extend in the correct order. Maybe the ./app/models version must interpret before the ./lib version. If so, the top of ./lib/my_model.rb should say require RAILS_ROOT + ''/app/models/my_model'', to get the correct one. Otherwise, the top of ./app/models/my_model could likewise require the ./lib version. But this opens the question why not put everything in one model? Either way, the "magic loader" system (aka "autorequire") will hide your app/model version if any interpretation sees the ./lib version first. The MyModel class name will be satisfied, and not trigger an auto-require. You must require the explicit app/model version at the top of any .rb file that you expect to correctly see it. Now, why are you trying to do this? -- Phlip http://www.oreilly.com/catalog/9780596510657/ "Test Driven Ajax (on Rails)" assert_xpath, assert_javascript, & assert_ajax --~--~---------~--~----~------------~-------~--~----~ 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 for your reply> Now, why are you trying to do this?I want to separate a complicated method outside of the model and to be able to "desactivate" it easily... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
More simply, isn''t it possible to define a class in two INDEPENDANT files? e.g., file1.rb: class A def m ; end end file2.rb class A def n; end end and I want - A to have the method m if only file1.rb was loaded - A to have the method n if only file2.rb was loaded - A to have both m and n if the two files were loaded --~--~---------~--~----~------------~-------~--~----~ 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 finally found my way out using a module and an include. It''s not completely independent but better than putting everything in the same place! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---