2009-05-22 82 views

回答

6

其實這並不難的。您可以只包含課程中的TextHelper模塊。

class MyLib 
    include ActionView::Helpers::TextHelper 

    def five_things(x) 
    pluralize 5, x 
    end 
end 

>> MyLib.new.five_things "dog" 
=> "5 dogs" 

,從從script/console會議上,我在lib定義一個類,輸出的,以確保它所有玩家不錯。

+2

奇怪的是這似乎並沒有工作,如果它是一個類的方法,如`高清自我.five_things(X)`。任何想法爲什麼? – 2011-06-09 23:24:34

0

對於那些似乎誰self方法不繼承從助手的功能,這將工作:

class MyLib 

    class << self 

    include Path::To::YourHelper 

    def test_func(x) 
     method_in_helper 5, x 
    end 

    end 

end