如何调用lib文件夹中的模块 [英] How to call modules in lib folder

查看:65
本文介绍了如何调用lib文件夹中的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Rails 新手,以防问题听起来很愚蠢,我的 lib 文件夹中有一个模块,但是如何调用控制器中的模块方法?

I'm new to rails just in case the question sounds stupid, I have a module in my lib folder, but how can I make calls to my module methods in a controller?

推荐答案

在 Rails 2.x 中,lib 目录自动包含在应用程序的加载路径中.从 Rails 3 开始,情况并非如此,但您可以在 config/application.rb 中编辑它以避免需要 'foo'":

In Rails 2.x lib directory was automatically included in the application’s load path. As of Rails 3, this isn't case, but you can edit this in config/application.rb to avoid the "require 'foo'" thing:

config.autoload_paths += %W(#{config.root}/lib)

这篇关于如何调用lib文件夹中的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆