Skip to content

Instantly share code, notes, and snippets.

@liwh
Created February 12, 2011 03:02
Show Gist options
  • Save liwh/823446 to your computer and use it in GitHub Desktop.
Save liwh/823446 to your computer and use it in GitHub Desktop.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
这是的 enviroment.rb 中的注释。如果自动加载就放在config/initializers。
很多东西只要留心就好了。
当然,如果要深入,就全面了解一下rails的加载过程吧。原则上,第三方(我们自己开发的东西,比如你这个文件或方法)开发的组件,是可以放在lib下了,只不过要配置一下。看看那些开源的项目,很多对rails自身的修改都习惯自己建立一个lib/patches包,方便管理。
只不过在用的使用,先要使用require "patches/youlibfile.rb"(前面没有lib/)就好了。
第三种方案,就是自己构建一个文件夹了,如在app的平级添加mylibs文件夹,在enviroment.rb使用config.load_paths += %w(#{RAILS_ROOT}/mylibs)就ok了
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment