我正在编写一个具有以下结构的助手;
module SomeHelper
def some_task(&block)
SomeMethods.new(self, block).some_task
end
class SomeMethods< Struct.new(:view, :callback)
delegate :content_tag, to: :view
include ActionView::Helpers::TextHelper
def some_task
content_tag :div do
concat content :div, class: 'a' do
Header
end
concat view.capture(&callback)
end
end
end
end
最终输出应该是一个div,它包含div.a和视图中辅助块中包含的html。我收到以下错误;
undefined local variable or method `output_buffer' for #<SomeHelper::SomeSomeMethods...
我该如何解决这个问题?
答案 0 :(得分:0)
以这种方式尝试:
def some_task
capture do
content_tag :div do # probably a typo unless you implemented a `content` method
concat content_tag :div, class: 'a' do
Header
end
concat view.capture(&callback)
end
end
end
答案 1 :(得分:0)
您需要将concat方法委托给查看对象