Rails 3 class available to view, controller and model
I 开发者_运维知识库am thinking about creating a new class that does URL shortening that can be called from the view, controller or model. Where should I put this class?
Such library should live in lib
and you need to require it in file you use it or globaly in config/application.rb
.
You can always dump it in config/initializers
unless you'd want to package it up as an independent gem.
If you place the class in /lib don't forget to make sure that it is autoloaded. In application.rb make sure you have a line like the following:
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += Dir["#{config.root}/lib/**/"]
精彩评论