私は次のことをしようとしています:
module ApplicationHelper
class PModuleHelper
include ActionView::Helpers::TagHelper
def heading(head = "", &block)
content = block_given? ? capture(&block) : head.to_s
content_tag :h3, content, :class => :module_header
end
end
def getmh
PModuleHelper.new
end
end
メソッドheading
またはブロックに文字列 (または記号) を指定します。
ビューで:
<% mh = getmh %>
<%= mh.heading :bla %> // WORKS
<%= mh.heading do %> // FAILS
test 123
<% end %>
(getmh
はこの例のためPModuleHelper
のものであり、アプリケーションの他のプロセスによって返されるため、これについてコメントしたりheading
、クラスメソッドではなく通常のヘルパーメソッドを作成することを提案したりする必要はありません)
残念ながら、私は常に次のエラーが発生します。
wrong number of arguments (0 for 1)
capture(&block)
コールの回線番号付き。
capture
独自のヘルパー クラス内で使用する方法は?