The field capture does not exist error in a plugin

Hi all,

I am writing a plugin with some view helpers. The helper method uses a
class internally to define the behaviour, but I can’t use content_tag
with a block inside that class.

This is the following code:

module Microformat
module ViewHelpers

# User will type:
# <% geo_for location, "Location:", :geo_tag => :div, :internal_tag

=> :span do |g| %>
# <% g.latitude "Latitude: #{location.latitude}, " %>
# <% g.longitude “Longitude: #{location.longitude}” %>
# <% end %>

# Output
#  <div class="geo">GEO:
#    <span class="latitude">342.386013</span>,
#    <span class="longitude">-90.082932</span>
#  </div>

def geo_for(object, text, options = {}, &proc)
  raise ArgumentError, "Missing block" unless block_given?
  containing_tag = options.delete(:tag) || :div
  internal_tag = options.delete(:internal_tag) || :span
  concat(tag(containing_tag, { :class => "geo" }, true),

proc.binding)
concat(text, proc.binding)
yield MicroformatCreator::GeoInternal.new(internal_tag, object)
concat("</#{containing_tag}>", proc.binding)
end

end

module MicroformatCreator

class InvalidMicroformatField < StandardError
end

class Microformat
  include ActionView::Helpers::TagHelper

  def initialize(tag, object)
    @internal_tag, @object = tag, object
  end

  def method_missing(name, *args)
    raise InvalidMicroformatField, "The field #{name} does not

exist" unless
@object.attribute_names.include?(name.to_s)
text = args.pop
content_tag @internal_tag, :class => name do
text unless text.nil?
end
end
end

class GeoInternal < Microformat

end

end
end

The error happens with the content_tag of method_missing of the
Microformat class, the exact message is ‘The field capture does not
exist’ and the module Microformat::ViewHelpers its included to
ActionView::Base when the plugin loads. content_tag as I’ve said works
if it is not passed a block.

Any ideas on how to get working content_tag in this situation would be
great!

Thanks,

Alan

Got past the field error by adding this

class Microformat
include ActionView::Helpers::TagHelper
include ActionView::Helpers::CaptureHelper
include ActionView::Helpers::TextHelper

but now _erbout is not defined in the scope of GeoInternal, are there
any way to make it available for the content_tag of the method_missing?

Alan