ruby on rails - How do I reference a custom class in lib from one of my models? -
if create file in lib/ called toast_mitten.rb, , in file have class called toastmitten, how use class models?
for example, inside method on comments class (one of models), if try call toastmitten.grasp, error uninitialized constant comment::toastmitten.
the class created intended dry repeated code in both models , rake task.
rails 3 doesn't autoload lib
the problem lib not being autoloaded. i'm using rails 3.0.0. apparently, rails team decided stop autoloading lib in rails 3, josé valim says here.
to load, added application.rb:
config.autoload_paths += %w(#{config.root}/lib) my colleague tells me other options be:
- add
config/initializers - explicitly
requirein model want use it
Comments
Post a Comment