ruby - When and where do I require files in a rails application? -
Assume that I have the following file in my lib directory of my Rail application:
# Lib / proxy.rb module SomeService class ServiceProxy def do_something end end end
If I want to use ServiceProxy in a model, I can use it like this: < / P> This works, but I think if I want to use serviceproxy in any other model I do not need it, then I do not need it. "Proxy Required" in the second model file "It appears that" in any model 'a proxy is required' it will add to the lookup path Update: Based on Floyd's answer below, And my service process file was saved as such, Then I need to explicitly file # app / model / product. Rb is known as 'Proxy' category product & lt; ActiveRecord :: Base Def do_something proxy = SomeService :: ServiceProxy.new Proxy.Do_Last End End
# lib / some_service / service_proxy.rb
There is a useful post about this problem.
In short, the Rail Autoloads Classes only follow the appropriate naming conventions in your Lib Dirty.
Comments
Post a Comment