Padrino无法在自定义表单构建器中使用输出助手

时间:2013-12-27 15:42:57

标签: ruby padrino

我正在尝试创建一个自定义表单构建器,该构建器生成带有错误消息的span。我一直收到消息

NoMethodError at /class/create
undefined method `content_tag' for #<Padrino::Helpers::FormBuilder::StandardFormBuilder:0x00000005aa24b8>

这是我的扩展名:

module Padrino
  module Helpers
    module FormBuilder
      class CustomFormBuilder < AbstractFormBuilder

        def errors_for(field)
          if object.errors[field.to_sym]
            error = object.errors[field.to_sym].first
            content_tag(:span, error, class: 'error')
          end
        end
      end
    end
  end
end

end

我已将此扩展名放在lib文件夹中。

1 个答案:

答案 0 :(得分:1)

您应该在构建器类中使用include辅助模块。

module Padrino
  module Helpers
    module FormBuilder
      class CustomFormBuilder < AbstractFormBuilder
        include TagHelpers
        include FormHelpers
        include AssetTagHelpers
        include OutputHelpers

        ...your methods here...
      end
    end
  end
end