On Friday 17 September 2010, Almog Friedman wrote: > i have a function that i wanna use in different models and i wanna do > it DRY. > so my best option as i see it is to include a module i made (that is > in the lib/ directory) in the model. > my code basicly looks something like this (for testing purpose, i > didn't implement my function yet) > lib/model_helper.rb > module ModelHelper > def bla > puts "hello world" > end > end > > app/models/test.rb > class Test < ActiveRecord::Base > include ModelHelper > end > > now the weird part is, when i try to do this in rails 2.2 it works > but when trying to do this in rails 3.0.0 it doesnt.
It ought to work in both versions just the same. You may need to be more specific what "not work" means. Also, it is relevant where that module is located. Rails 1.x and 2.x automatically load files from lib, rails 3.x does not. So if your ModelHelper is in lib/model_helper.rb you need to require that file explicitly where you use it. If the module is tied to your application anyway, I'd put it in app/models. In my opinion, app/models is not only for subclasses of ActiveRecord::Base, rather, it is the place where the model layer of an app resides. Michael -- Michael Schuerig mailto:[email protected] http://www.schuerig.de/michael/ -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

