且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我的非模型/非控制器代码应该放在哪里?

更新时间:2023-11-30 17:14:40

这就是lib"文件夹的用途.

This is what the 'lib' folder is for.

lib 文件夹在自动查找的路径中,所以你可以有

The lib folder is in the automatically looked up path, so you can have

class MyFoo
end

lib/my_foo.rb 中,然后只需调用

in lib/my_foo.rb and then just by calling

MyFoo.new

从控制器加载代码,不需要 require 'my_foo'

from a controller the code will be loaded without you needing a require 'my_foo'