Implicit argument passing of super from method defined by define_method() is not supported

jaycode picture jaycode · Apr 3, 2010 · Viewed 9.1k times · Source

In "Agile Web Development with Rails" (third edition) page 537 - 541 it has "Custom Form Builders" code as follows:

  class TaggedBuilder < ActionView::Helpers::FormBuilder
    # <p> # <label for="product_description">Description</label><br/> # <%= form.text_area 'description' %> #</p>
    def self.create_tagged_field(method_name) 
      define_method(method_name) do |label, *args|
        @template.content_tag("p" , @template.content_tag("label" , label.to_s.humanize, 
        :for => "#{@object_name}_#{label}") + "<br/>" + super)
      end
    end
    field_helpers.each do |name| 
      create_tagged_field(name)
    end 
  end

This code doesn't work with Ruby 1.9.1. It returns error as follows:

implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (ActionView::TemplateError)

My question is: What should I change in the code to fix this?

Answer

Marc-Andr&#233; Lafortune picture Marc-André Lafortune · Apr 3, 2010

The super above passed all parameters (see this recent question).

As the error message states, you must here "specify all arguments explicitly". Replace super with super(label, *args).