这是什么lib/
是为了.我有一个文件位于lib/deefour.rb
with
require "deefour/core_ext"
module Deefour; end
我将自定义方法放入lib/deefour/helpers.rb
module Deefour
module Helpers
extend self
def some_method
# ...
end
end
end
和核心猴子补丁lib/deefour/core_ext.rb
class String
def my_custom_string_method(str)
# ...
end
end
In config/initializers/deefour.rb
I put
require "deefour"
In your config/application.rb
确保你有
config.autoload_paths += Dir["#{config.root}/lib"]
最后,在ApplicationController
(对于控制器), ApplicationHelper
(查看),以及其他我需要的地方(即这里和那里的特定模型)我只是做
include ::Deefour::Helpers