不支持从 define_method() 定义的方法中传递 super 的隐式参数 [英] Implicit argument passing of super from method defined by define_method() is not supported

查看:43
本文介绍了不支持从 define_method() 定义的方法中传递 super 的隐式参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Agile Web Development with Rails"(第三版)第 537 - 541 页中,自定义表单构建器"代码如下:

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

此代码不适用于 Ruby 1.9.1.返回错误如下:

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

不支持从define_method() 定义的方法传递super 的隐式参数.明确指定所有参数.(ActionView::TemplateError)

我的问题是:我应该在代码中更改什么来解决这个问题?

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

推荐答案

上面的 super 传递了所有参数(参见这个 最近的问题).

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

如错误消息所述,您必须在此处明确指定所有参数".将 super 替换为 super(label, *args).

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

这篇关于不支持从 define_method() 定义的方法中传递 super 的隐式参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆