Skip to content

Instantly share code, notes, and snippets.

@Hampei
Created June 16, 2012 21:41
Show Gist options
  • Save Hampei/2942566 to your computer and use it in GitHub Desktop.
Save Hampei/2942566 to your computer and use it in GitHub Desktop.
Form helper for serialised attributes of type array-of-hashes.
module ActionView
module Helpers
class FormBuilder
# - f.fields_for_array_of_hashes :links do |lnk|
# .item
# = lnk.text_field :name
# = lnk.text_field :url
def fields_for_array_of_hashes(record_name, record_object = nil, options = {}, &block)
@object.send(record_name).each do |e|
e = OpenStruct.new(e)
def e.to_s; ''; end
@template.concat fields_for("#{record_name}[]", e, options, &block)
end
''
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment