Where should libraries go in Rails 3?

后端 未结 1 483
孤城傲影
孤城傲影 2021-01-06 04:18

Where\'s the recommended location for libraries in Rails 3? Is it as simple as \'lib\'?

I\'m not sure because \'lib\' seems more like a Rails 2 remnant, especially c

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-06 04:49

    lib is still the right place to put these kind of things.

    Autoloading lib was removed in Rails 3 because of the way engines work, but mainly because it's easy to just add it to the autoload_paths if you do want it automatically loaded and if not, you can require as needed. lib is still in the load path, so you don't need to specify where the module or class you're requiring is.

    You're correct, helpers are intended for the view, and would not be the place to put any model-related logic.

    I'd put the module in lib, and require and include it in your model as needed.

    0 讨论(0)
提交回复
热议问题