我只是想访问simple_format帮助器
class Note < ActiveRecord::Base
include SimpleHelper
def body_symbols_output_html
arc_simple_format(body_symbols_output)
end
和lib / simple_helper.rb
module SimpleHelper
def arc_simple_format txt
simple_format txt
end
end
并获取
NoMethodError (undefined method `simple_format' for #<Note:0x007f7fbb913088>):
lib/simple_helper.rb:4:in `arc_simple_format'
我如何访问simple_format?我知道访问视图级别的助手是一个坏主意,但这只是一个api
THX
答案 0 :(得分:6)
您应该只包含适当的模块:
include ActionView::Helpers::TextHelper
我建议的是避免使用所有这些方法破坏你的课程,这样你就可以在课堂上创建一个Helper课程:
class Note
delegate :simple_format, to: :helper
def helper
Helper.instance
end
private
class Helper
include Singleton
include ::ActionView::Helpers::NumberHelper
end
end