views:

26

answers:

1

I'm trying to generate a form from a parsed json (in Hash form) with this helper

def hash_to_form(hash, fields, legend)
    fields.fields_for do |b|
      concat('<fieldset><legend>', legend, '</legend>')
      hash.each do |key, attr|
        if hash[key].is_a? Hash
          hash_to_form(hash[key], b, key)
        else
          concat("<div class=\"field\">")
          concat(b.label(key, key))
          concat(b.text_field(key, :value => attr))
          concat("</div>")
        end
      end
    end
  end

But it's giving me an wrong number of argument( 0 for 1) when i try to call the helper method. Which makes no sense since it takes 3 arguments?

+2  A: 

It's not your helper that has the wrong number of arguments, it's your fields_for call:

fields.fields_for do |b|

This method takes an association name. If a user model has_many addresses, the method is called like this:

f.fields_for :addresses do |address_fields|

Fixing this should fix your helper.

Jaime Bellmyer