Supressing output from FormBuilder helpers?


#1

The FormBuilder helper is called like this:
<% field_validator :object, :name, {options} %>

The options hash is used to specify the different types of validation
for the field (required, numeric, regex, etc). This is where the
problem comes in as well. The helper eventually defers to the
following:

  def field_validator_tag(field_id, options={})
    # Raise an error if a requested validation type is not

recognized
raise(ArgumentError, “Missing validator options”) if
options.empty?
raise(ArgumentError, “Unrecognized validation options.
field_validator recognizes: #{FIELD_VALIDATIONS.join(’, ')}”) unless
(options.keys-FIELD_VALIDATIONS).empty?

    # Build up a string of the requested validations
    options.each do |validation_name, validation_options|

@field_validations.push( validation_constructor_string_omitted );
end
end

The problem is that a side effect of iterating over the options hash
is that the hash elements are emitted and end up on the page in the
place where the field_validator is called. That is, if I have
something like this:

<% validated_form_for :widget, :url=>widgets_path, :method=>:post %>

Age <%= f.text_field :age %> <%= field_validator :widget, :name, :required=>true, :numeric=>true %>

... <% end %>

I end up with rendered markup like this:

Age requiredtruenumerictrue

...

Any ideas how I can supress the output from the iteration?
(Incidentally, I know that it’s the iteration itself because I’ve
commented out the single line in the block and still get the keys
rendered in the page).