2011-03-03 66 views
3

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

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

在我的库/ my_library.rb

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

如何在库类使用助手的功能呢?

+0

CarHelper :: total_price(cars)?或CarHelper.total_price(汽车),我不记得确切 – apneadiving 2011-03-03 09:21:42

+0

你解决了如何做到这一点@梅隆 – 2015-03-13 18:15:34

回答

0

在您的MyLibrary类中包含CarHelper应该完成这项工作。

+0

你可能不得不要求帮助文件.. – rubyprince 2011-03-03 10:17:48

+0

这种方法失败total_price助手调用另一个助手。如何包括所有助手? – 2011-04-25 05:56:56