开发者

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/**/"]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜