开发者

Rails - Grails Service Equivalent

When yo开发者_如何学JAVAu want to write an internal service layer in Rails 3, where should you place the code? I'm coming from a Grails background and wondering what the service equivalent is in Rails.

Also, if this is covered in articles or online videos - would love to have the links. Thanks.


The Rails convention in this case is usually to put this stuff in the lib folder (ie; lib/services/erp_service.rb). I've created a 'Services' folder under the 'app' directory to contain services like this in the past as well. I don't believe you need to do anything extra to make the classes load, however if you want to put your services under the 'app' directory and they don't appear to be loading you can try messing with config.autoload_paths option from application.rb (in a Rails 3.x application)

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜