Where does one stick shared model code? I have a method that I want to share between models. What file should I define that method in if I want to keep DRY? Thanks, -scott --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
a module in the lib folder would be the right place i think then you can include it in the models -- 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 -~----------~----~----~----~------~----~------~--~---
in lib/my_cool_library.rb module MyCoolLibrary def my_cool_method puts "I do stuff that''s cool" end end Restart server now, in your models, just do class User < ActiveRecord::Base include MyCoolLibrary end This will "mix in" this code into your class, making it available to instance methods. user = User.new user.my_cool_method -Brian On Jan 2, 2008 11:35 AM, Scott <scott.gose-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Where does one stick shared model code? I have a method that I want > to share between models. What file should I define that method in if > I want to keep DRY? > > Thanks, > > -scott > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---