Lib 类中的用户帮助函数 [英] User helper functions in Lib classes

查看:23
本文介绍了Lib 类中的用户帮助函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 rails 3 中,是否可以在库类中使用辅助函数?例如,我有帮手:

In rails 3, is it possible to use helper functions in library classes? for example, I have helper:

module CarHelper
  def total_price(cars)
    #Do something here
  end
end

在我的 Lib/my_library.rb 中

In my Lib/my_library.rb

class MyLibrary
 def myFunc
   # I would like to use helper function total_price(cars) here
 end

结束

如何在 Lib 类中使用辅助函数?

How to use helper functions in Lib classes?

推荐答案

在 MyLibrary 类中包含 CarHelper 应该可以完成这项工作.

include CarHelper in your MyLibrary class should do the job .

这篇关于Lib 类中的用户帮助函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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